This is my code. When I run it, I get error:
java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
Can someone please help me?
form_()
{
setSize(265,500);
setVisible(true);
setLayout(new FlowLayout());
add(l1);
add(t1);
add(l2);
add(t2);
add(l3);
add(t3);
add(l4);
add(t5);
add(l5);
add(t4);
add(b);
b.addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource()==b) {
int x = 0;
String s1 = t1.getText();
String s2 = t2.getText();
String s3 = t3.getText();
char[] c = t5.getPassword();
String s5 = new String(c);
String s4 = t4.getText();
try {
Class.forName("com.mysql.cj.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false", "******", "********");
PreparedStatement ps = con.prepareStatement("INSERT INTO reg1 values(?,?,?,?,?");
ps.setString(1, s1);
ps.setString(2, s2);
ps.setString(3, s3);
ps.setString(4, s4);
ps.setString(5, s5);
int rs = ps.executeUpdate();
x++;
if(x>0)
{
JOptionPane.showMessageDialog(b,"Data saved Successfully");
}
} catch (Exception ex) {
System.out.println(ex);
}
}
}
}