How to code 'ADD' button to create new record in Java

I just started learning Java. I created a simple form using Java Swing on NetBeans. I added some text fileds and button like 'add', 'delete' etc. I am using MySql db. What I want to do is.. by clicking 'add' button the program should be able to create new records in customer table in MySql db.
From design tab, I clicked 'add' button and right click, select event, Actionperformed and wrote the following code.

Here is my code:
private void UpdateActionPerformed(java.awt.event.ActionEvent evt) {
         System.out.println("Adding new record");
         Connection con = null;
         String url = "jdbc:mysql://localhost:3306/";
         String db = "testdb";
         String driver = "com.mysql.jdbc.Driver";

         try {
             con = DriverManager.getConnection(url+db, "root","pw");
             PreparedStatement st=con.prepareStatement
               ("insert into customer (fNameValue,lNameValue) values(?;?)");
               (jPanel2, "Data is succesfully added");
         catch(Exception e) {
             JOptionPane.showMessageDialog(jPanel2,"Error in submitting");



    * @param args the command line arguments
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Customer().setVisible(true);
I am gettiing 'my exception message ... Error in submitting'

What am I doing wrong? Would it be possible to get a sample code on to create new rercords?

Thanks so much.
Who is Participating?
brunoguimaraesConnect With a Mentor Commented:
I think the problem is in these lines:


Change them too:


But it helps if you post the full exception stacktrace.
guavamayAuthor Commented:
Thanks for your help.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.