Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

adding data using a jframe form into mysql database

843859Mar 31 2006 — edited Apr 1 2006
hi i am having trouble inserting data into a MySQL database. the user is suppose to fill out a gui form made using swing compnents and then add all the contents from the textfield into the database.

it creates a new row but does not add any values for some unknown reason. i checked the contents of the table and everything is blank besides the incremented primary key..

here is the code below:
 private void btn_RegisterActionPerformed(java.awt.event.ActionEvent evt) {                                             

   String username = null;
   String password = null;
   String Re_pass = null;
   String email = null;
   
   username = fld_new_usename.getText();
   password = fld_password.getText();
   Re_pass = fld_retype.getText();
   email = fld_Email.getText();
        
        try 
        {
            Statement stmt;
            ResultSet rs;
            
            Class.forName("com.mysql.jdbc.Driver");
            
            String url = "jdbc:mysql://localhost:3306/i-comm";
            
            Connection con = DriverManager.getConnection( url,"root", "mankind");
            
            stmt = con.createStatement();
              stmt.executeUpdate(
                     "INSERT INTO users(Username, " +
                    "password, " + "Email) VALUES(username,password,email)");
              
              con.close();
            
        } catch( Exception e ) 
            {
                 e.printStackTrace();
            }//end catch// TODO add your handling code here:

    }                                            
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 29 2006
Added on Mar 31 2006
9 comments
2,415 views