I have made a basic swing application to input data into MySQL server. It is for some reason not accessing the driver to connect to the database. Here is the code. Thanks in advance for all the answers
import javax.swing.*;
import java.awt.event.*;
import java.sql.*;
public class Action extends JApplet {
public void init() {
}
public Action() {
JButton button = new JButton("Click here");
button.addActionListener(new EventHandler());
add(button);
}
}
public class EventHandler implements ActionListener{
public void actionPerformed(ActionEvent e) {
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
String url = "jdbc:mysql://localhost:3306/testgui";
Connection con= DriverManager.getConnection(url,"root", null);
String str = JOptionPane.showInputDialog(null,"Enter type");
String abc = JOptionPane.showInputDialog(null,"Enter number");
Statement st= con.createStatement();
st.executeUpdate("insert into tb1 values (null,'"+str+"',"+abc+")");
}
catch(Exception e1){
e1.printStackTrace();
}
}
}