• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Junilu Lacar
  • Martin Vashko
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Scott Selikoff
  • salvin francis
  • Piet Souris

CREATE table upon button click in eclipse

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to implement a sql statement into my eclipse code that creates/recreates a table when the 'intialize database' button is clicked. I believe my create statement is correct, but I am receiving no response when the button is clicked. Is there something wrong with my statement? Or am I missing something else in the code?


 
Sheriff
Posts: 24761
59
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would suggest extracting the database code from that program and writing a small program which does nothing but run the database code. It's a lot easier to test code which isn't encumbered by a lot of other unrelated code.

Let us know if you still have problems!
 
Saloon Keeper
Posts: 2806
367
Android Eclipse IDE Angular Framework MySQL Database TypeScript Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could also try using your same DDL command directly with the mysql command-line interface and see what happens there.

Also, visually inspect the command to confirm everything looks correct.
 
Taylor Manley
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you,
I now have the database create statements by themselves and linked to the interface with the button. One more question, since the tables are created once the button is pressed every button press thereafter throws the error "table already exists" is there a way to do away with this or have the table be recreated every time the button is pressed?

In case you need to see my code for the database now

 
Master Rancher
Posts: 4371
47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The answer to that is a case of what do you want it to do if the table already exists?

If it should DROP the existing table and recreate it then do that (if losing all the data that's in there is OK).
If it should ignore the error then do that.
If it should prompt the user then do that.

But you need to decide what it should do.
 
Sheriff
Posts: 6456
172
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After you've implemented what Dave Tolls suggested, try cleaning up the code.

* Try commenting out line 18, (Class.forName...)  I'd be surprised if you need it.  Now you don't need to catch Exception.
* Separate the one giant try/catch block into two blocks, one that catches the connection errors and one that catches the statement errors.
* Now you can use try with resources instead of the finally blocks.
* Format your code correctly.  Follow this link for HowToFormatCode.
 
The first person to drink cow's milk. That started off as a dare from this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!