-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTransaction.java
More file actions
63 lines (50 loc) · 1.42 KB
/
Transaction.java
File metadata and controls
63 lines (50 loc) · 1.42 KB
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
package transaction;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Types;
public class Transaction {
public static void main(String[] args) {
// TODO Auto-generated method stub
String url = "jdbc:mysql://localhost:3306/test";
String user = "u1";
String user_password = "123";
String sql="";
Connection conn=null;
Statement sta=null;
ResultSet rs;
try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection(url, user, user_password);
/*sta = conn.createStatement();
sql="insert into user(name,password) values 'tom','123'";
System.out.println(sql);
sta.executeUpdate(sql);*/
CallableStatement cs=conn.prepareCall("call p1(?,?,?)");
cs.setInt(1, 10);
cs.setInt(2,10);
cs.registerOutParameter(3, Types.INTEGER);
cs.executeUpdate();
//cs.executeQuery();
cs.getInt(3);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println(e.getErrorCode());//1213ËÀËø 1205³¬Ê±
System.out.println(e.getMessage());
try{
conn.rollback();
conn.close();
sta.close();
}catch(SQLException e1){
e1.printStackTrace();
}
}
}
}