This is a java inserting values to database problem.
I want to insert data into my database but I get an exception that states "Query does not return results". What am I doing wrong? What should I return?
This is my function code:
public void commitToDB(String fName) throws SQLException {
PreparedStatement preparedStatement = null;
ResultSet resultSet = null;
String query = "INSERT INTO users (firstname)" + " VALUES (?)";
try {
preparedStatement = connection.prepareStatement(query);
preparedStatement.setString(1, fName);
// execute the preparedstatement
resultSet = preparedStatement.executeQuery();
}
catch(Exception e) {
System.out.println("Got an exception");
System.out.println(e.getMessage());
}
finally {
preparedStatement.close();
resultSet.close();
}
}