zoukankan      html  css  js  c++  java
  • CLOB大数据对象

    处理CLOB大数据对象

    import java.sql.SQLException ;
    import java.sql.DriverManager ;
    import java.sql.ResultSet ;
    import java.sql.Connection ;
    import java.sql.PreparedStatement ;
    import java.io.File ;
    import java.io.FileInputStream;
    import java.io.InputStream ;
    class Tester
    {
        public static final String DBURL = "jdbc:mysql://localhost:3306/student" ;
    public static final String DBUSER = "root" ;
    public static final String DBPASS = "include" ;
    public static final String DBDRIVER = "org.gjt.mm.mysql.Driver" ;
    public static void main(String args[]) throws Exception
    {
      Connection con = null;
      PreparedStatement ps = null;
      String name="王呆萌" ;
      String sql = "insert into text(name,note) values(?,?)" ;
      Class.forName(DBDRIVER) ;
      con=DriverManager.getConnection(DBURL,DBUSER,DBPASS);//这句每次都会手残写错
      ps=con.prepareStatement(sql) ;
      File f =new File("d:"+File.separator+"in.txt") ;
      InputStream in =new FileInputStream(f);
      ps.setString(1,name) ;
      ps.setAsciiStream(2,in,(int)f.length());
      ps.executeUpdate();
      in.close();
      ps.close();
      con.close();
      System.out.println("操作成功!");
        }
    }



    读取CLOB大数据对象

     import java.sql.Connection ;
    import java.sql.SQLException ;
    import java.sql.DriverManager ;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet ;
    import java.io.InputStream ;
    import java.io.File ;
    import java.io.FileInputStream ;
    import java.util.Scanner ;
    class Tester
    {
        public static final String DBURL = "jdbc:mysql://localhost:3306/student" ;
    public static final String DBDRIVER = "org.gjt.mm.mysql.Driver" ;
    public static final String DBUSER = "root" ;
    public static final String DBPASS = "include" ;
    public static void main(String args[]) throws Exception
    {
       Connection con = null;
    PreparedStatement ps = null ;
    ResultSet rs = null;
    int id=1;
    String sql ="select name,note from text where id=?";
    con = DriverManager.getConnection(DBURL,DBUSER,DBPASS);
    ps=con.prepareStatement(sql) ;
    ps.setInt(1,id);
    rs=ps.executeQuery();
    if(rs.next())
    {
       String name = rs.getString(1);
    StringBuffer sb = new StringBuffer() ;
    System.out.println("名字 :"+name);
    InputStream in = rs.getAsciiStream(2) ;
    Scanner scan = new Scanner(in) ;  //点睛之笔
    scan.useDelimiter("
    ");
    while(scan.hasNext())
    {
      sb.append(scan.next()).append("
    ") ;
    }
    System.out.println(sb);
    in.close();
    }
    rs.close();
    ps.close();
    con.close();
    }
    }
    
    


  • 相关阅读:
    数据结构--线性表和链表的基础知识
    OC基础--字符串
    iOS开发知识梳理博文集
    OC基础--数据类型与表达式
    数据结构概述
    数据结构--栈和队列基础知识
    NodeJS Get/Post 参数获取
    NodeJS + express 添加HTTPS支持
    NodeJS 获取系统时间 并格式化输出
    Node.Js + Express 搭建服务器
  • 原文地址:https://www.cnblogs.com/emoji/p/4436840.html
Copyright © 2011-2022 走看看