• 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();
    }
    }
    
    


  • 相关阅读:
    字符串练习题
    js
    百度商桥--提供网站与用户之间交流平台
    git从本地上传到码云
    命名单词
    swiper 点击切换,拖动切换后继续自动轮播
    ionic4创建新项目
    两个年月日相减,获取年数和年数及半年数
    微信小程序点击跳转出现背景
    列表数据进行左浮动造成页面空白一块,排版错位问题
  • 原文地址:https://www.cnblogs.com/emoji/p/4436840.html
Copyright © 2020-2023  润新知