public class TestLongText {
//存储大文本
@Test
public void cunchu()throws Exception{
//获取连接对象
Connection conn = JdbcUtils2.getConn();
//获取执行对象 alt+shift+L
PreparedStatement pst = conn.prepareStatement("insert into tb1(book) values (?)");
//设置参数
FileReader fr = new FileReader("JdbcUtils2.java");
pst.setCharacterStream(1, fr);
//执行更新
int count = pst.executeUpdate();
System.out.println(count+"--->行受影响");
//关流
JdbcUtils2.close(null, pst, conn);
}
//读取大文本
@Test
public void duqu()throws Exception{
//获取连接对象
Connection conn = JdbcUtils2.getConn();
//获取执行对象 alt+shift+L
PreparedStatement pst = conn.prepareStatement("select * from tb1");
//执行查询
ResultSet rs = pst.executeQuery();
rs.next();
Reader reader = rs.getCharacterStream("book");
int s = -1;
while((s = reader.read()) != -1) {
System.out.print((char)s);
}
//关流
JdbcUtils2.close(null, pst, conn);
}
}
jdbc操作大文本
最新推荐文章于 2020-08-01 16:31:29 发布