jdbc oracle clob

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import java.io.BufferedReader;
import java.io.Reader;
import java.io.Writer;
import java.sql.CallableStatement;
import java.sql.Clob;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
 
public class Test {
    private static Connection getConn() {
        String driver = "oracle.jdbc.driver.OracleDriver";
        // String url = "jdbc:oracle:thin:@127.0.0.1:1521:pdbmyoracle";//
        // 设置连接字符串
        String url = "jdbc:oracle:thin:@//127.0.0.1:1521/pdbmyoracle";
        String username = "abc";// 用户名
        String password = "abc";// 密码
        Connection conn = null; // 创建数据库连接对象
        try {
            Class.forName(driver);
            conn = DriverManager.getConnection(url, username, password);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }
 
        return conn;
    }
 
    private static void query() {
        Connection conn = getConn();
        String sql = "select * from a";
        PreparedStatement pstmt;
        try {
            pstmt = conn.prepareStatement(sql);
            // 建立一个结果集,用来保存查询出来的结果
 
            ResultSet rs = pstmt.executeQuery();
 
            while (rs.next()) {
                String id = rs.getString("id");
                System.out.println(id);
 
                Clob clob = rs.getClob("content");
                Reader reader = clob.getCharacterStream();
                BufferedReader br = new BufferedReader(reader);
                StringBuffer sb = new StringBuffer();
                String s = "";
                while ((s = br.readLine()) != null) {
                    sb.append(s);
                    s = br.readLine();
                }
                System.out.println(sb.toString());
            }
            rs.close();
            pstmt.close();
            conn.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
    public static void callProcedure() {
        try {
            Connection con = getConn();
            CallableStatement cs = con.prepareCall("{call insert_a(?)}");
            Clob clob = con.createClob();
            Writer writer = clob.setCharacterStream(1);
            writer.write("106148,107161,104672,106903,105009,107667,104512,106715,105010,103265,104694,104695,104697,105053,108169,104189");
            writer.close();
            cs.setClob(1, clob);
            boolean b = cs.execute();
            System.out.println(b);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
    public static void main(String[] args) {
        callProcedure();
    }
 
}

jdbc oracle clob,布布扣,bubuko.com

jdbc oracle clob

上一篇:在使用vs2012中的MVC4出的错误!类型“System.Data.Entity.DbContext”在未被引用的程序集中定义


下一篇:利用log4j+mongodb实现分布式系统中日志统一管理