forked from prashantkalokhe/Hacktoberfest2022
-
Notifications
You must be signed in to change notification settings - Fork 0
/
program for CallableStatement statement with batch execution
76 lines (38 loc) · 1.63 KB
/
program for CallableStatement statement with batch execution
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
package com.java2novice.jdbc;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class MyBatchCallableStatement {
public static void main(String a[]){
Connection con = null;
CallableStatement callSt = null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
con = DriverManager.
getConnection("jdbc:oracle:thin:@<hostname>:<port num>:<DB name>"
,"user","password");
callSt = con.prepareCall("{call myprocedure(?,?)}");
callSt.setInt(1,200);
callSt.setDouble(2, 3000);
callSt.addBatch();
callSt.setInt(1,130);
callSt.setDouble(2, 2000);
callSt.addBatch();
int[] updateCounts = callSt.executeBatch();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally{
try{
if(callSt != null) callSt.close();
if(con != null) con.close();
} catch(Exception ex){}
}