我正在尝试在我的应用程序中创建私人聊天,但是当我尝试创建表时出现此错误:
org.postgresql.util.PSQLException:错误:“7”位置或附近的语法错误:14
代码:
public static String checkIfChatExists(String code, String friend) throws SQLException {
String i = LoginManager.checkCode(code);
if(i.equals("code-not-exists")) {
return "invalid-code";
}
ResultSet rs = conn.prepareStatement("SELECT * FROM pwchats").executeQuery();
while (rs.next()) {
if(rs.getString("user1").equals(i) && rs.getString("user2").equals(friend) || rs.getString("user1").equals(friend) && rs.getString("user2").equals(i)) {
return "exists";
}
}
PreparedStatement pre = conn.prepareStatement("INSERT INTO pwchats(user1, user2) VALUES(?, ?)");
pre.setString(1, i);
pre.setString(2, friend);
pre.execute();
PreparedStatement getChatId = conn.prepareStatement("SELECT * FROM pwchats WHERE user1 = ? AND user2 = ?;");
getChatId.setString(1, i);
getChatId.setString(2, friend);
ResultSet rss = getChatId.executeQuery();
while (rss.next()) {
PreparedStatement chat = conn.prepareStatement("CREATE TABLE " + rss.getInt("id") + "chat (username text NOT NULL, created_at timestamp with time zone NOT NULL DEFAULT now(), avatar text NOT NULL, message text NOT NULL, id serial NOT NULL);");
chat.execute(); //ERROR
return "done";
}
return "wat";
}
犯罪嫌疑人X
相关分类