-1
次のコードを使用してユーザーを登録しています。結果セットのためにPSQLExceptionがスローされました
@POST
@Path("/userreg")
@Consumes(MediaType.APPLICATION_JSON)
public Response userRegistration(String msg) {
String songString = "requesting";
JSONObject jsonObj = new JSONObject(msg);
ArrayList<Trending> output = new ArrayList<>();
PreparedStatement stmt = null;
try {
Connection connection = MyResource.getConnection();
String query = "SELECT * FROM users where username = ? OR mail = ?;";
PreparedStatement checkStmt = connection.prepareStatement(query);
checkStmt.setString(1, jsonObj.getString("username"));
checkStmt.setString(2, jsonObj.getString("mail"));
ResultSet rs = checkStmt.executeQuery();
if (rs.getString("username").equals(jsonObj.getString("username")) | rs.getString("mail").equals(jsonObj.getString("mail"))){
} else {
stmt = connection.prepareStatement(
"INSERT INTO USERS (username , mail , dob , age , gender , mac , ip , password , registration) VALUES(?, ? , ? , ? , ? , ? , ? , ? , ?) ;");
stmt.setString(1, jsonObj.getString("username"));
stmt.setString(2, jsonObj.getString("mail"));
stmt.setString(3, jsonObj.getString("dob"));
stmt.setString(4, jsonObj.getString("age"));
stmt.setString(5, jsonObj.getString("gender"));
stmt.setString(6, jsonObj.getString("mac"));
stmt.setString(7, jsonObj.getString("ip"));
stmt.setString(8, Utilities.randomAlphaNumeric(7));
stmt.setString(9, jsonObj.getString("registration"));
stmt.executeQuery();
}
songString = "success";
} catch (Exception ex) {
songString = "failure" + ex;
}
return Response.status(200).entity(songString).build();
}
イム次のエラーに
failureorg.postgresql.util.PSQLException取得:ResultSetが正しく に位置していないが、おそらくあなたは、次呼び出す必要があります。
これをどのように並べ替えることができますか?ユーザー名またはメールアドレスが既に存在するかどうか確認したいそれが存在する場合にのみ、私はユーザーに登録させたいと思っています。