Reputation: 61
in a swing button I set a action that it execute delete query and execute another class. here's my code:
JButton btnScanMyPc = new JButton("SCAN MY PC");
btnScanMyPc.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
try{
String q="DELETE FROM `search` WHERE 1=1 ";
PreparedStatement st=connection.prepareStatement(q);
ResultSet rs=st.executeQuery();
ReadDir rd = new ReadDir();
ReadDir.main(null);
}
catch(Exception e)
{JOptionPane.showMessageDialog(null, e);}
}
when i execute this query in database it works perfectly. but in java it shows some error like:
java.sql.SQLException: Can not issue data manipulation Statement with executeQuery().
Upvotes: 0
Views: 462
Reputation: 22972
You have to use executeUpdate()
instead of executeQuery()
for data manipulation like Insert
,Update
or Delete
.
Upvotes: 4