Connection con = null;
Statement stmt = null;
String url = "jdbc:sqlserver://127.0.0.1:1433;DatabaseName=db;user=sa;password=db123";// 要连接的数据库地址、数据库名、用户名和密码
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String strSql = "update student set id = 2 where num = '"+num+"'";
con = DriverManager.getConnection(url);//打开数据库连接
stmt = con.createStatement();
stmt.executeUpdate(strSql);
con.commit();//提交
stmt.close();
con.close();//关闭数据库连接
} catch (Exception e) {
e.printStackTrace();
}