private int insertOrUpdate(String sql, Object[] params) {
Connection conn = getConection();
PreparedStatement pstmt = null;
int i = 0;
try {
boolean ac = conn.getAutoCommit();
if (ac) {
conn.setAutoCommit(false);
}
pstmt = conn.prepareStatement(sql);
for (int j = 0; j < params.length; j++) {
pstmt.setObject(j + 1, params[j]);
}
i = pstmt.executeUpdate();
if (null == tb.get() || !tb.get()) {
conn.commit();
}
} catch (SQLException e) {
try {
conn.rollback();
} catch (SQLException e1) {
e.printStackTrace();
}
e.printStackTrace();
} finally {
close(pstmt);
if (null == tb.get() || !tb.get()) {
close(conn);
//System.out.println("close connection!");
}
}
return i;
}
此方法是一个单例类的方法 这个方法中Connection 已经用ThreadLocal改造成安全的了,想问一下这个方法中PreparedStatement pstmt 是否是安全的?