import java.sql.Connection;import java.sql.DriverManager;import java.sql.Statement;publicclassUpdateJdbc{publicstaticvoidmain(String[] args)throws Exception{final String DRIVER ="com.mysql.jdbc.Driver";final String URL ="jdbc:mysql://localhost:3306/testdb?useUnicode=true&characterEncoding=utf-8&useSSL=true";final String USERNAME ="root";final String PASSWORD ="123.";//加载驱动
Class.forName(DRIVER);//创建连接对象
Connection con = DriverManager.getConnection(URL,USERNAME,PASSWORD);//创建执行对象
Statement sta = con.createStatement();//创建SQL指令// String insertSql = "insert into test(testName,age,gender) value('周芷若',18,default)";// String deleteSql = "delete from test where testId between 2 and 4";// String UpdateSql = " update test set gender='女' WHERE testId=5";// String UpdateSql = "UPDATE TEST SET age='25' WHERE testId=1";
String UpdateSql ="UPDATE TEST SET testName='张佳佳' WHERE testId=1";// String insertSql = "insert into test(testName,age,gender) value('西施',18,'女')";//执行SQL执行int rst = sta.executeUpdate(UpdateSql);//根据不同返回值做不同的处理if(rst>0){
System.out.println("新增成功");}else{
System.out.println("新增失败");}}}