下面是我用来从数据库中获取值的代码:
try {
Class.forName("org.apache.derby.jdbc.ClientDriver").newInstance();
connect = DriverManager
.getConnection("jdbc:derby://localhost:1527/TedW;user=x;password=x;");
PreparedStatement statement = connect
.prepareStatement("SELECT * FROM USER");
resultSet = statement.executeQuery();
while (resultSet.next()) {
String user = resultSet.getString("Username");
String password = resultSet.getString("Password");
System.out.println("User: " + user);
System.out.println("ID: " + password);
}
} catch (Exception e) {
System.out.println(e);
}
问题是当我运行它时它显示异常:
java.sql.SQLSyntaxErrorException: Syntax error: Encountered "USER" at line 1, column 15.
我看到表名“USER”有一些问题。我在创建数据库时看到了它。在德比是 amde。下面是代码:
CREATE TABLE "USER"
(
"Id" INT not null primary key generated always as identity (START WITH 1, INCREMENT BY 1),
"Username" VARCHAR(20) NOT NULL,
"Password" VARCHAR(20) NOT NULL
);
我可能在哪里错了?我错过了什么吗?我可以对此有所了解吗?
谢谢。