public static int executeNotQuery(String sql) {
int num = 0;
// 1.得到链接对象
Connection conn = getConnection();
// 2.创建命令执行对象
Statement stm = null;
try {
stm = conn.createStatement();
// 3.执行sql脚本 得到返回值
num = stm.executeUpdate(sql);
} catch (SQLException e) {
e.printStackTrace();
} finally {
close(null, stm, conn);
}
return num;
}
int num = 0;
// 1.得到链接对象
Connection conn = getConnection();
// 2.创建命令执行对象
Statement stm = null;
try {
stm = conn.createStatement();
// 3.执行sql脚本 得到返回值
num = stm.executeUpdate(sql);
} catch (SQLException e) {
e.printStackTrace();
} finally {
close(null, stm, conn);
}
return num;
}
本文介绍了一个简单的Java方法,用于执行不返回查询结果的SQL语句(如INSERT, UPDATE, DELETE等),并返回受影响的行数。该方法首先获取数据库连接,然后通过Statement对象执行SQL语句。
303

被折叠的 条评论
为什么被折叠?



