码迷,mamicode.com
首页 > 其他好文 > 详细

CLOB大数据对象

时间:2015-01-12 09:29:43      阅读:105      评论:0      收藏:0      [点我收藏+]

标签:

处理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("\r\n");
while(scan.hasNext())
{
  sb.append(scan.next()).append("\n") ;
}
System.out.println(sb);
in.close();
}
rs.close();
ps.close();
con.close();
}
}



CLOB大数据对象

标签:

原文地址:http://blog.csdn.net/u012566693/article/details/42614085

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!