• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Cannot create a new table

 
Craig Parsons
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a GUI set up so the user can enter SQl commands. I have two tables set up in an Access DB. I have been able to do query commands OK as well as insert and delete but have been having problems with drop table and create table. Everytime I try to create a table it says that table already exists but I know it doesn't. If I try to drop the table I get an error say that the table doesn't exist.
Part of my problem is I don't fully understand how drop and create commands work. Below is the code I am using to execute any SQL commands entered. I have some extra displays in there to help me troubleshoot the problem.
Any suggestions?
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So perhaps you better post your SQL-Statement?
And may you test it with another database?
 
Craig Jackson
Ranch Hand
Posts: 405
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

boolean blnResponse = statement.execute(strQuery);
//QUERY
if (blnResponse) {
sqlResults = statement.executeQuery(strQuery);

Based on the above code it appears you executing the same SQL command
twice. So if you for example say drop a table, the first time the command
will succeed, the second time it will say something like the table does not exist.
I hope this helps.
Craig.
 
Craig Parsons
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks CJ.
I removed
sqlResults = statement.executeQuery(strQuery); AND
rowCount = statement.executeUpdate(strQuery);
Things seem to working now.
By the way is there a way to tell if you are Dropping a table or creating one?
Thanks,
Craig
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34665
366
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Craig,
The easiest way would be to look at the sql before you run the statement to see if it begins with "create" or "drop."
 
Craig Parsons
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok I'll give that a try.
Thanks for your help.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic