aspose file tools*
The moose likes JDBC and the fly likes Connection Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Connection Problem" Watch "Connection Problem" New topic
Author

Connection Problem

Bob Young
Ranch Hand

Joined: Dec 23, 2000
Posts: 65
I am trying to run a book example from Beginning Java 2 on the JDBC chapter and I am having trouble getting the example to run. I am using the downloaded database and example. I set up the Data Source Name in the ODBC Microsoft Access setup (Access 2000, on win 98), and the classpath contains the rt.jar. The database is ok, I can open it and look at the tables. What
needs to be included or changed for me to get this to work? Thanks.

import java.sql.*;
public class TestTheConnection
{
public static void main(String[] args)
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

String sourceURL = "jdbc dbc:technical_library";
Driver theDriver = DriverManager.getDriver(sourceURL);
int verMajor = theDriver.getMajorVersion();
float verComplete = Float.parseFloat(verMajor + "" + theDriver.getMinorVersion());
System.out.println("sourceURL version: " + verComplete);

Connection databaseConnection =
DriverManager.getConnection(sourceURL);
}
catch(ClassNotFoundException cnfe)
{
System.err.println(cnfe);
}
catch(SQLException sqle)
{
System.out.println("SQLException: " + sqle.getMessage());
sqle.printStackTrace();

}
}
}
sourceURL version: 21.0
SQLException: [Microsoft][ODBC Microsoft Access Driver] '(unknown)' is not a valid path.
Make sure that the path name is spelled correctly and that you are connected to the server on
which the file resides.
java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] '(unknown)' is not a valid path.
Make sure that the path name is spelled correctly and that you are connected to the server on which
the file resides.
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6031)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:6188)
at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(JdbcOdbc.java:2458)
at sun.jdbc.odbc.JdbcOdbcConnection.initialize(JdbcOdbcConnection.java:320)
at sun.jdbc.odbc.JdbcOdbcDriver.connect(JdbcOdbcDriver.java:163)
at java.sql.DriverManager.getConnection(DriverManager.java:517)
at java.sql.DriverManager.getConnection(DriverManager.java:199)
at TestTheConnection.main(TestTheConnection.java:22)
Wayne L Johnson
Ranch Hand

Joined: Sep 03, 2003
Posts: 399
It would help to know what kind of datasource you are trying to connect to. The only clue here is in the exception:
Make sure that the path name is spelled correctly and that you are connected to the server on
which the file resides.

My guess is that the ODBC connection is referencing a file/system that is not available or doesn't exist. The "DriverManager.getDriver(...)" doesn't try and resolve the connection, but simply polls the drivers to find one that can handle the URL (jdbc dbc:...). Only when you do the "getConnection(...)" does it try and connect to the underlying data source.
Look at the ODBC definition for "technical_library" and make sure its parameters are valid.
Bob Young
Ranch Hand

Joined: Dec 23, 2000
Posts: 65
Thanks Wayne for the reply. I did not get a chance to post an earlier reply that I solve the problem. All I needed to do was go in and remove the DNS for the access database and reenter it. I have no idea why it did not work the first time as the path was exactly the same. The data base is only in one location and the spelling is/was correct. I did play with it and you can get the error if you misspell the URL.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Connection Problem