954,549 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

GUI database query drop row error

Hi guys I am able to drop my tables that I want but however when I come to trying to drop rows the rows do not delete. I have tried the following which have all produced the same error duplicate key TABLENAME :

Any help you can give for a solution would be very helpful

1. String writeString3 = "DROP TABLE "+t;

2. String writeString3 ="DELETE FROM"+t+"where NAME="+t ;

3. String writeString3 ="DELETE FROM"+t+"where NAME=1" ;

4. String writeString3 ="DELETE FROM TABLENAME WHERE NAME = '1'";

5. String writeString3 ="DROP TABLE testing "; //// it works but when I try

6. String writeString3 ="DROP TABLE"+t; // it gives same error


My code that I have used can be seen below:

if (e.getSource() == DELETERECORDS) {
           String t = TABLENAME.getText();
            String v = NAME.getText();
          
      String writeString3 ="DROP TABLE testing ";    
            try {
                
                myStatement.executeUpdate(writeString3);
                TABLENAME.setText("");
                
            } catch (SQLException sqle) {
                showMessageDialog(this, "Duplicate key " + t);
            }
             TABLENAME.setText("");
     }
TIM_M_91
Junior Poster in Training
58 posts since Feb 2012
Reputation Points: 18
Solved Threads: 0
 

Print the stacktrace of the Exception. That might help you out on why it is unable to go ahead with the delete or drop statements.

Secondly I believe that that 2,3 in your list of possibilities cause Syntax Errors

String writeString3 ="DELETE FROM"+t+"where NAME="+t ;
String writeString3 ="DELETE FROM "+t+"where NAME="+t ;

Notice the extra space after FROM

Sky Diploma
Practically a Posting Shark
865 posts since Mar 2008
Reputation Points: 673
Solved Threads: 131
 

Print the stacktrace of the Exception. That might help you out on why it is unable to go ahead with the delete or drop statements.

Secondly I believe that that 2,3 in your list of possibilities cause Syntax Errors

String writeString3 ="DELETE FROM"+t+"where NAME="+t ;
String writeString3 ="DELETE FROM "+t+"where NAME="+t ;

Notice the extra space after FROM

Thanks for the reply and help all sorted now

TIM_M_91
Junior Poster in Training
58 posts since Feb 2012
Reputation Points: 18
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: