I'm working on a Java project and I've hit a wall regarding inserting values into my table. I wanted to have a check before inserting into this table to see if there were any duplicates.
I've tried an executeUpdate with a resultset for executequery afterwards, but I'm getting "java.sql.SQLException: Can not issue data manipulation statements with executeQuery()."
Here is the code I'm working with, thank you in advanced!
public void registernow(ActionEvent actionEvent) throws IOException, SQLException {
ConnectionClass registerClass = new ConnectionClass();
Connection register = registerClass.getConnection();
try {
Statement registerStatement = register.createStatement();
String sql = "INSERT INTO userAuth (username, password) VALUES ('" + txt_username.getText() + "' , '" + txt_password.getText() + "')";
registerStatement.executeUpdate(sql);
ResultSet resultSet = registerStatement.executeQuery(sql);
if (resultSet.next()) {
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("register.fxml"));
Parent fxmlregister = (Parent) fxmlLoader.load();
Stage stage = new Stage();
stage.setTitle("COMP228 Project Registration Complete!");
stage.setScene(new Scene(fxmlregister));
stage.show();
} else {
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("registerfailed.fxml"));
Parent fxmlregisterfailed = (Parent) fxmlLoader.load();
Stage stage = new Stage();
stage.setTitle("COMP228 Project Registration Failed!");
stage.setScene(new Scene(fxmlregisterfailed));
stage.show();
}