Issue
i am facing a problem related with SQL or i don't know,here is my Database Handler class, where i am connecting it:
public class DatabaseHandler extends Configs{
Connection dbCon;
public Connection getDbCon() throws ClassNotFoundException, SQLException {
String connectionString = "jdbc:mysql://" + dbHost +":"
+dbPort +"/"+dbName;
Class.forName("com.mysql.cj.jdbc.Driver");
dbCon= DriverManager.getConnection(connectionString,dbUsername,dbPassword);
return dbCon;
}
public void SignUpUser( String name, String surname, LocalDate date, String mobile,
String login, String password){
String insert = "INSERT INTO users (name, surname, dob, mobile,login, password)" +
"VALUES(?,?,?,?,?,?)";
PreparedStatement statement = null;
try {
statement = getDbCon().prepareStatement(insert);
statement.setString(1,name);
statement.setString(2,surname);
statement.setDate(3, Date.valueOf(date));
statement.setString(4,mobile);
statement.setString(5,login);
statement.setString(6,password);
} catch (SQLException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
and this is my Controller class where i am doing actions with my button :
@FXML
void btnRegistration(ActionEvent event) {
String login = txtLoginRegistration.getText();
String name = txtNameRegistration.getText();
String surname = txtSurnameRegistration.getText();
LocalDate date = txtDateRegistration.getValue();
String mobile = txtMobile.getText();
String password = txtPasswordRegistration.getText();
//Connect to DB
DatabaseHandler handler = new DatabaseHandler();
handler.SignUpUser(name,surname,date,mobile,login,password);
Extending Coonfigs class , i have just declared the variables name of DB There is no any error while compiling it , even i did all the operations with the Try and Catch , but anyway while checking my DB it is not inserted, I would be glad for any answers, Hope i did not regret you with my answer , if i did, i apologize.
Solution
Oh, i just found my mistake i just forget to put
statement.executeUpdate();
At the end of the statements
Answered By - Feliks Bekeshov
Answer Checked By - Terry (JavaFixing Volunteer)