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("");
     }

Recommended Answers

All 2 Replies

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.