aspose file tools*
The moose likes JDBC 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
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Cannot create a new table" Watch "Cannot create a new table" New topic
Author

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?


http://home.arcor.de/hirnstrom/bewerbung
Craig Jackson
Ranch Hand

Joined: Mar 19, 2002
Posts: 405

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

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?
Thanks,
Craig
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31079
    
163

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."


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, 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: http://aspose.com/file-tools
 
subject: Cannot create a new table