ORACLE用JDBC操作CLOB
来源:互联网 发布:什么是审计作业软件 编辑:程序博客网 时间:2024/05/21 14:48
public class ClobTest { static String url = "jdbc:oracle:thin:@10.12.10.18:1521:orcl"; static String user = "cwbe1_9999"; static String pwd = "or777"; static String text = "这是要插入到CLOB里面的数据,更新数据!" + "update"; private static int clobImport() throws ClassNotFoundException, SQLException { DriverManager.registerDriver(new OracleDriver()); Connection conn = DriverManager.getConnection(url, user, pwd);// 得到连接对象 String sql = "insert into ETLNEEDPARAM(F_KEY,F_VALUE) values ('defaultpo',?)";// 要执行的SQL语句 PreparedStatement stmt = conn.prepareStatement(sql);// 加载SQL语句 // PreparedStatement支持SQL带有问号?,可以动态替换?的内容。 Reader clobReader = new StringReader(text); // 将 text转成流形式 stmt.setCharacterStream(1, clobReader, text.length());// 替换sql语句中的? int num = stmt.executeUpdate();// 执行SQL if (num > 0) { System.out.println("ok"); } else { System.out.println("NO"); } stmt.close(); conn.close(); return num; } private static int clobUpdate(String key) throws ClassNotFoundException, SQLException { DriverManager.registerDriver(new OracleDriver()); Connection conn = DriverManager.getConnection(url, user, pwd);// 得到连接对象 String sql = "update ETLNEEDPARAM set F_VALUE = ? where F_KEY = ? ";// 要执行的SQL语句 PreparedStatement stmt = conn.prepareStatement(sql);// 加载SQL语句 // PreparedStatement支持SQL带有问号?,可以动态替换?的内容。 Reader clobReader = new StringReader(text); // 将 text转成流形式 stmt.setString(2, key); stmt.setCharacterStream(1, clobReader, text.length());// 替换sql语句中的? int num = stmt.executeUpdate();// 执行SQL if (num > 0) { System.out.println("ok"); } else { System.out.println("NO"); } stmt.close(); conn.close(); return num; } private static String clobExport() throws ClassNotFoundException, SQLException, IOException { CLOB clob = null; String sql = "select F_VALUE from ETLNEEDPARAM where F_KEY ='test1'"; DriverManager.registerDriver(new OracleDriver()); Connection conn = DriverManager.getConnection(url, user, pwd);// 得到连接对象 PreparedStatement stmt = conn.prepareStatement(sql); ResultSet rs = stmt.executeQuery(); String content = ""; if (rs.next()) { clob = (oracle.sql.CLOB) rs.getClob("F_VALUE"); // 获得CLOB字段str // 注释: 用 rs.getString("str")无法得到 数据 ,返回的 是 NULL; content = ClobToString(clob); } stmt.close(); conn.close(); return content; } // 将字CLOB转成STRING类型 public static String ClobToString(CLOB clob) throws SQLException, IOException { String reString = ""; Reader is = clob.getCharacterStream();// 得到流 BufferedReader br = new BufferedReader(is); String s = br.readLine(); StringBuffer sb = new StringBuffer(); // 执行循环将字符串全部取出付值给StringBuffer由StringBuffer转成STRING while (s != null) { sb.append(s); s = br.readLine(); } reString = sb.toString(); return reString; } public static void main(String[] args) throws IOException,ClassNotFoundException, SQLException { // System.out.println(clobImport()); System.out.println(clobUpdate("fmo")); System.out.println(clobUpdate("epo")); // System.out.println(clobExport()); }
0 0
- ORACLE用JDBC操作CLOB
- JDBC操作Oracle CLOB对象
- 用JDBC来测试Oracle Clob 字段
- jdbc操作blob,clob
- JDBC CLOB\BLOB操作
- jdbc操作blob,clob
- 通过JDBC 操作 ORACLE BLOB,CLOB字段类型
- 使用JDBC操作基于Oracle的CLOB,BLOB字段类型
- (转)通过JDBC 操作 ORACLE BLOB,CLOB字段类型
- JDBC 对oracle 的clob ,blob类型的操作方式
- 利用JDBC操作Oracle CLOB和BLOB类型数据
- JDBC 对oracle 的clob ,blob类型的操作方式
- jdbc学习:操作Oracle的CLOB和BLOB数据
- 【ORACLE JDBC】Oracle中使用JDBC对CLOB操作,传说中关于666限制问题
- JDBC 处理Oracle Clob字段
- Oracle jdbc 插入 clob blob
- JDBC操作Clob,Blob字段
- hibernate操作Oracle CLOB
- Kibana User Guide [4.2] » Visualize » Markdown Widget
- 使用JavaMail接收邮件的示例
- 自定义滑动到底部自动加载SwipeRefreshLayout
- 解析OBJ模型并将其加载到Unity3D场景中
- maven导出项目依赖的jar包
- ORACLE用JDBC操作CLOB
- 第九章 控制抽象
- iOS开发者遇到审核失败的原因及解决办法
- ie6,ie7常见兼容性问题总结
- js日期时间选择器bootstrap
- Unity3D游戏开发之C++插件接入
- 程序员的10大职业谏言
- hdu5567解题报告/#63 (div.2) 1001
- 在ubuntu上软件安装的几种格式dev,rpm,bin,tar.gz