GeeCON Prague 2014*
The moose likes JDBC and the fly likes Creating New SQL DB Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » JDBC
Bookmark "Creating New SQL DB" Watch "Creating New SQL DB" New topic
Author

Creating New SQL DB

Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

I am fairly new at the world of JDBC and SQL. While doing some reading, I have noticed that it seems one must create an SQL database outside of JAVA and then use JDBC to access and manipulate the DB. I was wondering if there was a way, that if SQL was running as a service, there is a way in JAVA to create the DB? Maybe I just overlooked something??
Thanks for any help.

------------------
Happy Coding,
Gregg Bolinger


GenRocket - Experts at Building Test Data
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
Yes, you can create your table(s) from within java. Check out the CREATE TABLE SQL command of the Statement Interface.

Bosun


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

I know I can create my tables, but can I actually create the DB itself. The way you access the DB is by the name of the DB. What if you want the user to specify a DB name and create a new one.

------------------
Happy Coding,
Gregg Bolinger
Chantal Ackermann
Ranch Hand

Joined: Sep 28, 2000
Posts: 508
hi Gregg,
I believe that there exist DB frontends working with JDBC. they need to have the ability to create databases?!
maybe that depends on the db, as well. PostgreSQL has a shellscript createdb to be used outside of the postgres and thus outside of any db environment. but mysql hasn't such a script, I think. what I want to say is: maybe you can create dbs while you're already connected to one. that would solve the problem, wouldn't it?
chantal
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

I tried creating while connected to one, then switched databases. The only problem with that is the fact that there will have to be a default DB on the system created outside of my program. But I can probably figure out a work around. I think MySQL creates a couple of databases on install, so I will probably just connect to one of those by default.
Thanks

------------------
Happy Coding,
Gregg Bolinger
 
GeeCON Prague 2014
 
subject: Creating New SQL DB