wood burning stoves 2.0*
The moose likes JDBC and the fly likes Using JDBC to discover dbase information Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Using JDBC to discover dbase information" Watch "Using JDBC to discover dbase information" New topic
Author

Using JDBC to discover dbase information

Jeremy Quartey
Greenhorn

Joined: Jan 10, 2002
Posts: 11
I would be very grateful for any responses even with brief comments if possible.
How would you use the JDBC to discover information about a database that needs to be accessed when the only information you have is its location at a remote computer, the name of the tables which make up the database and the location of the computer.
I am sure it is a very simple answer but I cant figure out how to create a URL for the getConnection() method without the database name or if indeed this is the issue.
Do you need to have the database name (with passwords etc) or can you access the tables directly via the ResultSet object using fileURL ?
I cant see how to arrive at the parameters for the getConnection() method in the following expression:
DriverManager.getConnection(fileURL,"Username","password");
The JDK1.3 refers to the getConnection()method as:
public static Connection getConnection(String�url,
String�user,String�password)throws SQLException
How could I discover the following information using JDBC or are they actually required
url - a database url of the form jdbc:subprotocol:subname
user - the database user on whose behalf the connection is being made
password - the user's password
JDK1.3 documentation says that "To obtain a DatabaseMetaData object you use the method getMetaData() found in the Connection class" but how can I use this without a connection to the database in the first place.

How can theResultSetMetaData provide the name of the database in order to create the URL without a connection-or how do you create the necessary connection?
I know that the getURL(), getUserName(), getDatabaseProductName(), getConnection() methods of DatabaseMetaData interface will give me some useful information but how is this done without a connection to the database in the first place.
Any feedback would be very much appreciated
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

I have been looking for a solution to this as well. And haven't found one.
I think that the Authors of the JDBC API assumed that if you were connecting to a Database, the Database Name, UserName, and Password for that Database should be known.
I do not like this however because it makes it a little more difficult to write a DB Client using JDBC.
I usually use MySQL-Front for managing my MySQL Databases. And it will connect to the MySQL Server without knowing the name of the Database you want to connect to. I would like to have that option in JDBC, but don't.
The only work around that I know of is the fact that there should always be a Database named MySQL (for MySQL Server that is). Most other DBMS's do have a defult DB that is shipped with the server (Northwind for Ms SQL). So you could always connect to it, then use DatabaseMetaData, ResultSetMetaData, etc to get the rest of the information. And utalize the USE DBName SQL statement to change databases.
I would love a better solution though.


GenRocket - Experts at Building Test Data
 
Don't get me started about those stupid light bulbs.
 
subject: Using JDBC to discover dbase information
 
Similar Threads
User name and password?
DB2 700 and 701 - Test Sample
Parameters on Oracle JDBC URL
MySQL & JDBC
jdbc to get schema user information