0

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("");
     }
2
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by TIM_M_91
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

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

Thanks for the reply and help all sorted now

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.