This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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
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.