I have this code below for connecting to the database named judicial but it's not working.
package Project;
import java.sql.*;
public class ConnectionProvider {
public static Connection getCon()
{
try
{
Class.forName("com.mysql.jdbc.Drver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/judicial","root", "");
return con;
}
catch(Exception e)
{
return null;
}
}
}
this is the code for the button
import Project.ConnectionProvider;
import java.sql.*;
import javax.swing.JOptionPane;
public class addNewCriminalRecord extends javax.swing.JFrame {
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String criminalID=jTextField1.getText();
String name=jTextField2.getText();
String contactNumber=jTextField3.getText();
String age=jTextField4.getText();
String gender=(String)jComboBox1.getSelectedItem();
String address=jTextField5.getText();
String crimeType=jTextField6.getText();
String anyMajorCrime=jTextField7.getText();
try{
Connection con=ConnectionProvider.getCon();
Statement st=con.createStatement();
st.executeUpdate("insert into criminal values('"+criminalID+"','"+name+"','"+contactNumber+"','"+age+"','"+gender+"','"+address+"','"+crimeType+"','"+anyMajorCrime+"')");
JOptionPane.showMessageDialog(null, "Successfully Updated!");
setVisible(false);
new addNewCriminalRecord().setVisible(true);
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, "Please enter Judicial data in the correct format!");
}
}
Please help on how or where I went wrong. Because whenever I run the pade and input some details, it gives me the caught error. I have xampp up and running.