【发布时间】:2017-01-08 21:55:37
【问题描述】:
目前我正在使用 h2 嵌入式数据库为学生数据库开发 Java 应用程序。我只想知道如何使用用户输入更新密码。
Scanner sc=new Scanner(System.in);
String username,password,user="admin",pass;
System.out.println("User name:");
username=sc.next();
System.out.println("Password:");
password=sc.next();
Class.forName("org.h2.Driver");
Connection c=DriverManager.getConnection("jdbc:h2:database",username ,password);
Statement s=c.createStatement();
System.out.println("Enter new password:");
pass=sc.next();
s.execute("alter user "+user+" identified by "+pass);
上面给出的是部分sn-p,它在执行时显示以下错误:
线程“main”org.h2.jdbc.JdbcSQLException 中的异常:SQL 语句“ALTER USER ADMIN IDENTIFIED[*] BY POPPER”中的语法错误;预期“设置,重命名,管理员”; SQL 语句: 更改 popper [42001-176] 识别的用户管理员
【问题讨论】:
-
你读过精美的手册吗? h2database.com/html/grammar.html#alter_user_set_password 您可能还想使用准备好的语句或 escape 用户并通过