I have a mySQL database named Customer that I am trying to insert data from a textfield in a GUI. I ran the code below and in the console it said "Connected Successfully" with no errors. I checked to see if the information had been inserted into the Customer table of my mySQL database and nothing was inserted. Does anyone know why?
button.setOnAction(e -> {
Connection dbConnection = null;
PreparedStatement preparedStatement = null;
try {
Customer cust = new Customer();
dbConnection = Connect();
String sql="Insert into CIS3270.Customer(firstName,lastName, email,userNAME,Address,Zip,State,SecurityQ, Password, ConfirmPassword,SSN)VALUES (?,?,?,?,?,?,?,?,?,?,?)";
preparedStatement = dbConnection.prepareStatement(sql);
preparedStatement.setString(1,cust.getFirstName());
preparedStatement.setString(2,cust.getLastName());
preparedStatement.setString(3,cust.getEmail());
preparedStatement.setString(4,cust.getUserNAME());
preparedStatement.setString(5,cust.getAddress());
preparedStatement.setString(6,cust.getZip());
preparedStatement.setString(7,cust.getState());
preparedStatement.setString(8,cust.getSecurityQuestion());
preparedStatement.setString(9,cust.getPassWORD());
preparedStatement.setString(10,cust.getConfirmPassword());
preparedStatement.setString(11,cust.getSSN());
preparedStatement.executeBatch();
preparedStatement.executeUpdate();
dbConnection.close();
preparedStatement.close();
LoginScreen loginPage = new LoginScreen();
loginPage.start(primaryStage);
}
catch(Exception e1) {
e1.printStackTrace();
}
});
public static Connection Connect() {
Connection con = null;
try {
Class.forName("com.mysql.jdbc.Driver");
con = (Connection) DriverManager.getConnection("jdbc:mysql://(ip adress):3306/CIS3270", "root", "password");
} catch (Exception e) {
System.out.println("Can not connect");
}
if (con != null) {
System.out.println("Connected Successfully");
}
return con;
}
Connect()