public class class3 {
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
//1.链接数据库
Class.forName ("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection con = DriverManager.getConnection("jdbc:sqlserver://192.168.8.60;DataBaseName=School","sa","123456");
//3.用定义好的SQL语句输出数据库信息
Statement sta = con.createStatement();
//2.数据库SQL语句
String sql = "update [Student] set [stuName] = '小花', [sex] = '男', [age] = '50' where [classid] = '1' ";
sta.executeUpdate(sql);
//4.判断是否更改成功
if(!sta.execute(sql)){
System.out.println("数据更改成功");
}else{
System.out.println("数据没更改");
}
//5.关闭数据库
sta.close();
con.close();