File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes DB Connection with no DB Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "DB Connection with no DB" Watch "DB Connection with no DB" New topic

DB Connection with no DB

Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15302

Has anyone ever found a way to connect to a DBMS without specifying the Database Name initially? I know that doesn't make sense because of the way a Connection works in JDBC. But here is a possible scenerio that may help.
What if someone deletes all the Databases in an SQL database? Is there no way in JAVA using JDBC to connect to the DBMS and create a new one?
Also, I know that with MySQL I can always choose test or MySQL by default. And with MS SQL Northwind is a safe bet. But can someone tell me some other defaults for some of the other DBMS' out there. Like Oracle, Postgre, etc?

GenRocket - Experts at Building Test Data
Rodney Woodruff
Ranch Hand

Joined: Dec 04, 2001
Posts: 80
You can definitely use jdbc to connect to a database and create a new instance. Look around for java database management tools.
While I am not certain as to whether this works or not, this is how would envision doing it:
1. Create a Connection to the database
2. Create a Statement object
3. Use the statement object to execute your database creation query/script.
Give it a try and see how it works.

Hope This Helps
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15302

Did you read my question?
The JDBC API specifies that when creating a Connection object, you have to specify the Database Name to Connect to.
I know I can connect to a Database then do a "USE" command to specify another database after I have created it.
However, what if there are no databases created? Then what do you provide in the Connection object to create a Connection if it requires a DB name?
Thanks for responding though.
I agree. Here's the link:
subject: DB Connection with no DB
It's not a secret anymore!