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());
    }                              

Looking at your SQL statement (line 37) it lookslike you have a comma right at the end - just before the closing )
Maybe that's the syntax error?

Thank you JamesCherrill. I've deleted the comma on line 37, but once I ran the program again yet another error: java.sql.SQLException: Column count doesn't match value count at row 1

Is there something I missed in my query? Do my columns on MySQL database have to match the order of values on line 37?

I got the code to work by setting the placements of the values into the right order which they appear on the sql database. Thank you!

main observation here: don't do this. NEVER create SQL statements this way, ALWAYS use PreparedStatements or better yet JPA.
Prevents a lot of problems.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.