• 大对象数据LOB的应用


    概述

      由于无结构的数据往往都是大型的,存储量特别大,而LOB(large object)类型主要用来支持无结构的大型数据。

      用户可以利用LOB数据类型来存储大型的无结构数据,特别是文本,图形,视频和音频等多媒体数据,

      系统还提供了随机访问这些LOB数据类型的有效方法。

    LOB数据类型可以分为以下几种:

    • BLOB:二进制LOB类型,用于存放无结构的二进制数据,最大4GB。
    • CLOB:字符LOB类型,用于存放字符数据,最大可以存储4GB。
    • NLOB:字符LOB类型,和CLOB相同,支持国家字符集。
    • BFILE:二进制文件类型,与数据外的操作系统文件相关联,该文件存储二进制大对象。

    使用LOB类型数据的限制:

    •   系统不支持分布式LOB,用户不能在SELECT子句或WHERE子句中使用远程LOB定位器,也不能在DBMS_LOB包的子程序中使用远程定位器

        ,也不能引用包含LOB属性的远程表中的对象.

    • LOB列不能用于聚集表.
    • LOB列不能出现在查询语句的GROUP BY,ORDER BY ,DISTINCT(去重复)之后,也不允许出现在分组函数和连接函数中.

    • LOB类型不能出现在数组的定义中.4

    • LOB类型不能够出现在建有分区索引的表中.

    • NCLOB类型不能作为对象类型的属性,当可以作为对象类型的方法的参数类型.

    JDBC连接数据库的主要步骤:

    • Class.forName("com.mysql.jdbc.Driver");//反射 类对象 四种
    • 获取连接 Connection conn=DriverManager.getConnection(URL,USER,PASSWORD);
    • 编写SQL语句并发送 PrepapredStatement pstm=conn.prepareStatement(sql);
    • 获得数据库返回结果 (ResultSet rs) 增删改(int)
    • 关闭资源 public static void closeResource(Connection conn,PreparedStatement pstm,ResultSet rs)

    工具类 方法:封装,设置为静态方法,好处,调用方便.(代码)

    package com.guigu.jdbc;
    
    import java.sql.*;
    
    public class MySQLConnectionUtil {
        private static String DRIVER="com.mysql.jdbc.Driver";
        private static String URL="jdbc:mysql://127.0.0.1:3306/lob";
        private static String USERNAME="root";
        private static String PASSWORD="123456";
    
        public static Connection getConnection(){
            Connection connection=null;
            try {
                Class.forName(DRIVER);
                connection= DriverManager.getConnection(URL,USERNAME,PASSWORD);
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            } catch (SQLException e) {
                e.printStackTrace();
            }
            return connection;
        }
    
        public static void close(Connection connection, PreparedStatement preparedStatement, ResultSet resultSet){
    
                try {
                    if(resultSet!=null){
                    resultSet.close();
                    }
                    if (preparedStatement!=null){
                        preparedStatement.close();
                    }
                    if (connection!=null){
                        connection.close();
                    }
                } catch (SQLException e) {
                    e.printStackTrace();
                }
    
        }
    }
    package com.guigu.jdbc;
    
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.InputStream;
    import java.sql.Connection;
    import java.sql.PreparedStatement;
    import java.sql.SQLException;
    
    public class JDBCMySQLCOLBWriter {
        public static void main(String[] args) {
            String sql="INSERT INTO TEXTCLOB VALUES (?,?,?)";
            Connection connection=MySQLConnectionUtil.getConnection();
            PreparedStatement preparedStatement=null;
            try {
                 preparedStatement=connection.prepareStatement(sql);
                 File file =new File("D:/workspace/site.txt");
                 //使用输入流读写文本文件
                InputStream inputStream=new FileInputStream(file);
                //加载SQL语句中VALUES占位符参数
                preparedStatement.setInt(1,1);
                preparedStatement.setString(2,"site.txt");
                preparedStatement.setAsciiStream(3,inputStream);
                int count = preparedStatement.executeUpdate();
                if(count>0){
                    System.out.println("数据插入成功");
                }else{
                    System.out.println("数据插入失败");
                }
    
            } catch (SQLException e) {
                e.printStackTrace();
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }finally {
                MySQLConnectionUtil.close(connection,preparedStatement,null);
            }
        }
    }

    心得:

       哪有那么多“天注定” 所有看似幸运和巧合的事都来源于悄悄努力,

       你的人生是默默无闻还是光彩显赫,完全取决于你自己。

  • 相关阅读:
    VmWare 安装 Centos
    将博客搬至CSDN
    如何快速学习新的知识
    Git使用说明--常用命令
    App 冷启动:给 Android 的 Activity 添加一个背景
    Proguard中optimize设置不当引发SimException
    完美解决android软键盘监听
    修改Activity的继承类导致程序闪退
    非技术相关的面试技巧(文章内容来自他人博客)
    Android面试题(文章内容来自他人博客)
  • 原文地址:https://www.cnblogs.com/dyywht/p/13622470.html
Copyright © 2020-2023  润新知