This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes JDBC and Relational Databases and the fly likes Cannot create a new table Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Cannot create a new table" Watch "Cannot create a new table" New topic

Cannot create a new table

Craig Parsons
Ranch Hand

Joined: Jan 28, 2004
Posts: 40
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

Joined: Jun 02, 2003
Posts: 1923

So perhaps you better post your SQL-Statement?
And may you test it with another database?
Craig Jackson
Ranch Hand

Joined: Mar 19, 2002
Posts: 405

boolean blnResponse = statement.execute(strQuery);
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 Parsons
Ranch Hand

Joined: Jan 28, 2004
Posts: 40
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?
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33132

The easiest way would be to look at the sql before you run the statement to see if it begins with "create" or "drop."

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Craig Parsons
Ranch Hand

Joined: Jan 28, 2004
Posts: 40
Ok I'll give that a try.
Thanks for your help.
I agree. Here's the link:
subject: Cannot create a new table
It's not a secret anymore!