0

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().
5
  • 1
    That error message could not be more clear, right? Commented May 1, 2015 at 3:22
  • yeah this error message is not clear. Commented May 1, 2015 at 3:25
  • kon was saying that the error message is clear Commented May 1, 2015 at 3:30
  • @RakibAlHasan The error message is extremely clear, if you would just read it. It clearly explains what you are doing incorrectly. Commented May 1, 2015 at 3:34
  • sorry sir i did not understand what you said first. but now its clear. and sir i am learning so its not so much easy for me to understand . Commented May 1, 2015 at 3:40

2 Answers 2

4

You have to use executeUpdate() instead of executeQuery() for data manipulation like Insert,Update or Delete.

Sign up to request clarification or add additional context in comments.

2 Comments

sir i tried but its not working.. error: type mismatch cannot convert from int to ResultSet.
Yes as this method does not return resultset.You will get the number of rows affected by your query as a result.So store result of executeUpdate in int variable.Please go to the executeUpdate link for more detail.
1

try this one

 "DELETE FROM search WHERE 1=1 "

 st.executeUpdate(q);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.