Hello guys. I'm trying to create a registration form that takes in employee information. The error I'm getting is: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1
I'm still trying my hand at working with MySQL and Netbeans. Here's what I have so far:
DBConnection.java
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
public class DBConnection {
private Connection DBConnection;
public Connection connect (){
try{
Class.forName("com.mysql.jdbc.Driver");
System.out.println("Connection Success!");
}
catch(ClassNotFoundException cnfe){
System.out.println("Connection Failed!" + cnfe);
}
String url = "jdbc:mysql://localhost:3306/bel-air";
try{
DBConnection = DriverManager.getConnection(url,"root", "");
System.out.println("Database Connected!");
}
catch(SQLException se){
System.out.println("No Database!" + se);
}
return DBConnection;
}
public void WriteToDatabase(String firstname, String lastname, String midInitial, String gender, String teleNum, String mobNum, String username, String password){
try{
String url = "jdbc:mysql://localhost:3306/bel-air";
DBConnection = DriverManager.getConnection(url,"root", "");
Statement sta = DBConnection.createStatement();
int s = sta.executeUpdate("INSERT INTO employees VALUES('" + firstname + "', '" + lastname + "', '" + midInitial + "', '" + gender + "','" + teleNum + "', '" + mobNum + "','" + username + "', '" + password + "',)");
System.out.println("Inserted into database!");
}
catch(Exception e){
System.out.println(e);
}
}
}
And here's my RegistrationForm.java:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Object obj = evt.getSource();
if(obj == jButton1){
jTextField1.setText("");
jTextField2.setText("");
jTextField3.setText("");
jTextField4.setText("");
jTextField5.setText("");
jTextField6.setText("");
jPasswordField1.setText("");
}
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
DBConnection db = new DBConnection();
db.WriteToDatabase(jTextField1.getText(), jTextField3.getText(), jTextField2.getText(), jComboBox1.getSelectedItem() + "", jTextField5.getText(), jTextField6.getText(), jTextField4.getText(), jPasswordField1.getText());
}