public static void main(String[] args) {
Connection conn=null;
PreparedStatement ps=null;
try {
//加载驱动
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
//获取链接
conn=DriverManager.getConnection("jdbc:sqlserver://localhost;database=studb", "sa", "123456");
//删除
//编写sql语句
String sql = "delete from stu where id=?";
//获取PreparedStatement对象
ps=conn.prepareStatement(sql);
//给?赋值
ps.setInt(1, 2);
//执行
int i=ps.executeUpdate();
if(i>0){
System.out.println("成功");
}else{
System.out.println("失败");
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} finally{
//关闭链接
try {
ps.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
本文地址:https://blog.csdn.net/weixin_44374620/article/details/107597254
如对本文有疑问, 点击进行留言回复!!
PLSQL Developer 13 报错“数据库字符集(AL32UTF8)和客户端字符集(2%)是不同的。字符集转化可能会造成不可预期的后果“
SQL注入--利用floor(rand(0)*2)报错返回信息
Oracle SQL nvl(),listagg() within group(),TO_CHAR(),CASE WHEN THEN ELSE END
SqlServer2008实例32全文索引和全文目录之从全文索引中去掉普通字符串
网友评论