JDBC读取OracleBlob数据
数据库
2018-06-02 08:32:36
阅读次数: 0
- public static void main(String[] args) throws Exception {
-
-
- Class.forName("oracle.jdbc.driver.OracleDriver");
-
- Connection con = DriverManager.getConnection(
-
- "jdbc:oracle:thin:@192.168.0.68:1521:myOracle", "my", "123");
-
- con.setAutoCommit(false);
-
- Statement st = con.createStatement();
-
-
-
- ResultSet rs = st.executeQuery(
-
- "select content from user_content where id = 2");
-
- if (rs.next()) {
-
- java.sql.Blob blob = rs.getBlob(1);
-
- InputStream ins = blob.getBinaryStream();
-
-
-
- File file = new File("d:\\output.txt");
-
- OutputStream fout = new FileOutputStream(file);
-
-
-
- byte[] b = new byte[1024];
-
- int len = 0;
-
- while ((len = ins.read(b)) != -1) {
-
- fout.write(b, 0, len);
-
- }
-
-
-
- fout.close();
-
- ins.close();
-
- con.commit();
-
- con.close();
- }
- }
- }
转载自jayyanzhang2010.iteye.com/blog/1544229