private final static String USER = "bank";
private final static String PASS = "jfy12345";
Connection conn = null;
PreparedStatement cmd = null;
try {
// 1.加载驱动
new oracle.jdbc.driver.OracleDriver();
// 2.建立连接
conn = DriverManager.getConnection(URL, USER, PASS);
// 3.准备语句
cmd = conn.prepareStatement(sql);
if (paras != null) {
for (int i = 1; i <= paras.length; i++) {
cmd.setObject(i, paras[i - 1]);
}
}
// 4.执行驱动
cmd.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e.getMessage());
} finally {
// 5.关闭资源
try {
if (cmd != null) {
cmd.close();
}
if (conn != null) {
conn.close();
}
} catch (Exception e) {
}
}