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");
String sql = "delete from stu where id=?";
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();
}
}
}