更新数据库的数据记录(JAVA)(修改密码)

时间:2022-06-27 05:51:18
 1 package org.lxh.demo17.statementdemo;
 2 
 3 import java.sql.Connection;
 4 import java.sql.DriverManager;
 5 import java.sql.SQLException;
 6 import java.sql.Statement;
 7 
 8 public class resetPassword {
 9     private static final String DBDRIVER = "com.mysql.jdbc.Driver";
10     private static final String DBURL = "jdbc:mysql://localhost:3306/mldn";
11     private static final String DBUSER = "root";
12     private static final String DBPASS = "root";
13     public static void main(String[] args) throws ClassNotFoundException, SQLException {
14         Connection conn = null;
15         Statement stmt = null;
16         String sql = "update emp set ename='jjjj' where empno=123";
17         System.out.println("wanchengSQLyuju");
18         Class.forName(DBDRIVER);
19         conn = DriverManager.getConnection(DBURL, DBUSER, DBPASS);
20         stmt = conn.createStatement();
21         stmt.executeUpdate(sql);
22         stmt.close();
23         conn.close();
24     }
25 
26 }