This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Svelte and Sapper in Action and have Mark Volkmann on-line!
See this thread for details.
Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

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?


 
Marshal
Posts: 25823
69
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!
 
Marshal
Posts: 3181
466
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus 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: 4668
49
  • 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: 7108
184
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.
 
    Bookmark Topic Watch Topic
  • New Topic