public void batRunRequest(String _toApplicationId, String _toEventId, String _fromEventId, String _userId) throws DataConnectException, DataAccessException, DataPropertyException {
Connection con = getConnection();
String jobId = null;
String jobGroupId = null;
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
String systemDate = dateFormat.format(new Date());
try {
con.setAutoCommit(false);
PreparedStatement pst = null;
ResultSet rs = null;
try {
pst = con.prepareStatement(JOB_ID_SEQ);
rs = pst.executeQuery();
while (rs.next()) {
jobId = systemDate + String.format("%07d", Integer.value(rs.getString(1)));
}
} finally {
try{
if (rs != null) {
rs.close();
}
}finally{
if (pst != null) {
pst.close();
}
}
} try {
pst = con.prepareStatement(JOB_GROUP_ID_SEQ);
rs = pst.executeQuery();
while (rs.next()) {
jobGroupId = systemDate + String.format("%07d", Integer.valueOf(rs
.getString(1)));
}
} finally {
try{
if (rs != null) {
rs.close();
}
}finally{
if (pst != null) {
pst.close();
}
}
} try {
pst = con.prepareStatement(SQL_BAT_KANRI_INSERT);
pst.setString(1, jobGroupId);
pst.setString(2, jobId);
pst.setString(3, _toApplicationId);
pst.setString(4, _toEventId);
pst.setString(5, _fromEventId);
pst.setString(6, _userId);
pst.executeUpdate();
} finally {
if (pst != null) {
pst.close();
}
} try {
pst = con.prepareStatement(SQL_BAT_PARAMETER_INSERT);
pst.setString(1, jobId);
pst.executeUpdate();
con.commit();
} finally {
if (pst != null) {
pst.close();
}
}
} catch (SQLException e) {
if (con != null) {
try {
con.rollback();
} catch (SQLException e1) {
throw new DataAccessException(e.getMessage(), e);
}
}
throw new DataAccessException(e.getMessage(), e);
}
}
Connection con = getConnection();
String jobId = null;
String jobGroupId = null;
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
String systemDate = dateFormat.format(new Date());
try {
con.setAutoCommit(false);
PreparedStatement pst = null;
ResultSet rs = null;
try {
pst = con.prepareStatement(JOB_ID_SEQ);
rs = pst.executeQuery();
while (rs.next()) {
jobId = systemDate + String.format("%07d", Integer.value(rs.getString(1)));
}
} finally {
try{
if (rs != null) {
rs.close();
}
}finally{
if (pst != null) {
pst.close();
}
}
} try {
pst = con.prepareStatement(JOB_GROUP_ID_SEQ);
rs = pst.executeQuery();
while (rs.next()) {
jobGroupId = systemDate + String.format("%07d", Integer.valueOf(rs
.getString(1)));
}
} finally {
try{
if (rs != null) {
rs.close();
}
}finally{
if (pst != null) {
pst.close();
}
}
} try {
pst = con.prepareStatement(SQL_BAT_KANRI_INSERT);
pst.setString(1, jobGroupId);
pst.setString(2, jobId);
pst.setString(3, _toApplicationId);
pst.setString(4, _toEventId);
pst.setString(5, _fromEventId);
pst.setString(6, _userId);
pst.executeUpdate();
} finally {
if (pst != null) {
pst.close();
}
} try {
pst = con.prepareStatement(SQL_BAT_PARAMETER_INSERT);
pst.setString(1, jobId);
pst.executeUpdate();
con.commit();
} finally {
if (pst != null) {
pst.close();
}
}
} catch (SQLException e) {
if (con != null) {
try {
con.rollback();
} catch (SQLException e1) {
throw new DataAccessException(e.getMessage(), e);
}
}
throw new DataAccessException(e.getMessage(), e);
}
}
Connection conn=DBConnection.getConn();
Statement pst=null;
try{
conn.setAutoCommit(false);// 更改JDBC事务的默认提交方式
StringBuffer sql=new StringBuffer();
StringBuffer rsql=new StringBuffer();
sql.append("delete from SysFun where id in ( "+ids[0]);
rsql.append("delete from Raul where sysFunid in ( "+ids[0]);
pst=conn.createStatement();
if(ids!=null&&ids.length>0){
// System.out.print(delValues.length);
for(int i=1;i<ids.length;i++){//自动判断勾选时参数?的个数
sql.append(","+ids[i]);
}}
sql.append(")");
rsql.append(")");
pst.executeUpdate(rsql.toString());
pst.executeUpdate(sql.toString());
pst=conn.createStatement();
conn.commit();//提交JDBC事务
conn.setAutoCommit(true);// 恢复JDBC事务的默认提交方式
return true;
}catch (Exception e) {
try {
conn.rollback();//回滚JDBC事务
} catch (SQLException e1) {
e1.printStackTrace();
}
e.printStackTrace();
return false;
}
finally{
if(pst!=null){
try {
pst.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
DBConnection.Close(conn);
}
}看看吧!我以前做的了!不知道行不!
2.
3.
4.
5.Java代码
6.private PreparedStatement psStmt1;
7.private PreparedStatement psStmt2;
8.private PreparedStatement psStmt3;
9.
10.........................
11.........................
12.
13./* 关闭代码 */
14.public void cleanup() throws SQLException {
15. SQLException exception = null;
16. if (psStmt1 != null) {
17. try {
18. psStmt1.close();
19. } catch (SQLException e) {
20. exception = e;
21. } finally {
22. psStmt1 = null;
23. }
24. }
25.
26. if (psStmt2 != null) {
27. try {
28. psStmt2.close();
29. } catch (SQLException e) {
30. if (exception != null) e.setNextException(exception);
31. exception = e;
32. } finally {
33. psStmt2 = null;
34. }
35. }
36.
37. if (psStmt3 != null) {
38. try {
39. psStmt3.close();
40. } catch (SQLException e) {
41. if (exception != null) e.setNextException(exception);
42. exception = e;
43. } finally {
44. psStmt3 = null;
45. }
46. }
47.
48. if (exception != null) {
49. throw exception;
50. }
51.}
52.
53.private PreparedStatement psStmt1;
54.private PreparedStatement psStmt2;
55.private PreparedStatement psStmt3;
56.
57.........................
58.........................
59.
60./* 关闭代码 */
61.public void cleanup() throws SQLException {
62. SQLException exception = null;
63. if (psStmt1 != null) {
64. try {
65. psStmt1.close();
66. } catch (SQLException e) {
67. exception = e;
68. } finally {
69. psStmt1 = null;
70. }
71. }
72.
73. if (psStmt2 != null) {
74. try {
75. psStmt2.close();
76. } catch (SQLException e) {
77. if (exception != null) e.setNextException(exception);
78. exception = e;
79. } finally {
80. psStmt2 = null;
81. }
82. }
83.
84. if (psStmt3 != null) {
85. try {
86. psStmt3.close();
87. } catch (SQLException e) {
88. if (exception != null) e.setNextException(exception);
89. exception = e;
90. } finally {
91. psStmt3 = null;
92. }
93. }
94.
95. if (exception != null) {
96. throw exception;
97. }
98.}
欣赏一下吧
你的SQL已经执行完成了 这时候关闭它应该问题不大
不过我看你都是在finally里面close的 finally是最后执行的一般都是在这里关闭你的代码里面怎么那么多try嵌套··
Statement 相当语句
这是面向对象的思想,没有难的