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();
}
} |
相关文章
- 06-06Jmeter ForEach Controller and JDBC
- 06-06JDBC更新数据中文乱码问题(无法更新数据 也不报错)
- 06-06JDBC连接出错Sat Oct 24 12:36:27 CST 2020 WARN: Establishing SSL connection without server‘s identity ver
- 06-06关于JDBC的一些建议
- 06-06使用Spring Cache Abstraction和JDBC DAO进行交易
- 06-06JDBC中的Statement和PreparedStatement的区别
- 06-06JDBC的PreparedStatement是什么?
- 06-06.JDBC的PreparedStatement是什么?
- 06-06JDBC的PreparedStatemen
- 06-063、SpringBoot整合之SpringBoot整合JDBC