Reputation: 31
So I'm relatively new to databases in java and I recently encountered this problem while trying to add a username, password and email to my database from a Jframe login page.
Also the method that executes the SQL is in a separate class from the GUI and I just call the method from the btn action method in the GUI class.
Here's my Method
public void RegisterUser(String u, String p, String m) {
int num;
try {
String qry = "INSERT INTO tblUsers(Username,Password,E-Mail Address)"
+ " VALUES ('" + u + "','" + p + "','" + m + "')";
PreparedStatement pstmt = conn.prepareStatement(qry);
num = pstmt.executeUpdate();
pstmt.close();
} catch (Exception e) {
e.printStackTrace();
}
}
Thanks :)
Upvotes: 0
Views: 532
Reputation: 31
The problem was in the database connection, when running a query the connection fails if the database name has a space in between words
Upvotes: 0