对数据库进行增删改查操作
程序员文章站
2022-03-02 22:23:26
...
改:
Connection connection=null;
PreparedStatement ps=null;
ResultSet rs=null;
Scanner scanner = new Scanner(System.in);
System.out.println("请输入要修改的信息的用户名:");
String u=scanner.nextLine();
System.out.println("请输入要修改的信息的密码:");
String p=scanner.nextLine();
try {
Class.forName("com.mysql.jdbc.Driver");
connection=DriverManager.getConnection("jdbc:mysql://localhost:3306/jiejie","root","root");
ps=connection.prepareStatement("update u_p set pw=? where username=?");
ps.setString(1,u );
ps.setString(2, p);
ps.executeUpdate();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}