• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Connection Problem

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)
 
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic