I'm relatively new to java and have just started learning chow to connect mysql to java. This is my code to add details entered in java to a table in mysql:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
String Name = t1.getText();
String Mobile = t2.getText();
String Email = t3.getText();
try
{
Class.forName("java.sql.DriverManager");
Connection con;
con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/cbse", "Mahima" , "mahima");
Statement stmt = (Statement) con.createStatement();
String query = "INSERT INTO contact VALUES ('"+Name+"','"+Mobile+"', '"+Email+"');";
stmt.executeUpdate(query);
}
catch(Exception e)
{
JOptionPane.showMessageDialog(this, e.getMessage());
}
}
How to fix the error??