JDBC读取CLOB
编程技术  /  houtizong 发布于 3年前   91
import java.sql.*;import java.io.*;public class ReadClob {public static void main(String[] args) {PreparedStatement pstmt = null;ResultSet rset = null;BufferedReader reader = null;Connection conn = null;String driver = "oracle.jdbc.driver.OracleDriver";String strUrl = "jdbc:oracle:[email protected]:1521:ORCL";try {Class.forName(driver);conn = DriverManager.getConnection(strUrl, "scott", "tiger");pstmt = conn.prepareStatement("select v_clob form ord where ORD_id =?");pstmt.setInt(1, 1);rset = pstmt.executeQuery();while (rset.next()) {Clob clob = rset.getClob(1);// java.sql.Clob类型reader = new BufferedReader(new InputStreamReader(clob.getAsciiStream()));String line = null;while ((line = reader.readLine()) != null) {System.out.println(line);}}} catch (ClassNotFoundException e) {e.printStackTrace();} catch (SQLException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();}}}
//写入操作String stmtString = "select v_clob form ord where ord_id =? for update";pstmt = conn.prepareStatement(stmtString);pstmt.setInt(1, 2);rset = pstmt.executeQuery();while(rset.next()){//造型为oracle.sql.CLOBCLOB clob = (CLOB)rset.getClob(1);String newClobDate = new String("NEW CLOOB DATE");Writer writer = clob.getCharacterOutputStream();//OutStream writer = clob.getAsciiOutputStream();writer.write(newClobDate);}
请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!
技术博客集 - 网站简介:
前后端技术:
后端基于Hyperf2.1框架开发,前端使用Bootstrap可视化布局系统生成
网站主要作用:
1.编程技术分享及讨论交流,内置聊天系统;
2.测试交流框架问题,比如:Hyperf、Laravel、TP、beego;
3.本站数据是基于大数据采集等爬虫技术为基础助力分享知识,如有侵权请发邮件到站长邮箱,站长会尽快处理;
4.站长邮箱:[email protected];
文章归档
文章标签
友情链接