File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes jdbc-odbc bridge problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "jdbc-odbc bridge problem" Watch "jdbc-odbc bridge problem" New topic
Author

jdbc-odbc bridge problem

clyde jones
Ranch Hand

Joined: Dec 02, 2000
Posts: 46
Hi,
I don't know what's going on. I'am using access97 with a win98 os. I have created a database with the ODBC Data Source Administrator. I have checked the rt.jar file for JDBCDriver.classes and it's there. When I run a program to view the Database, I get this exception.
Exception in thread "main" java.lang.NoClassDefFoundError:
I have checked and double checked the properties file I am using and everything looks good.
I have a simular problem when I try to read a mySql database(this is a JDBC driver problem). I have a copy of the driver that I need and the CLASSPATH is set in my auto exec file. Any suggetions would be appreciated. I"M STUMPED!
Thanks,
Clyde
anand rk
Greenhorn

Joined: Feb 07, 2001
Posts: 25
Hi,
If u have created an aaplication and u r getting this problem then try setting the class path
set classpath=%classpath%;"ur directory path";
This is in addition to ur existing classpath settings.I have also xperienced this problem and was successfully by trying this.
bye
Anand
clyde jones
Ranch Hand

Joined: Dec 02, 2000
Posts: 46
Anand,
Thanks for your help. I changed my auto exec's CLASSPATH to the following:
set CLASSPATH=%CLASSPATH%;C:\JDK1.3\sun\jdbc\odbc\JdbcOdbc.class;.
I am trying to write the path to the JdbcOdbc.class. Do you know if this is correct?
Clyde
anand rk
Greenhorn

Joined: Feb 07, 2001
Posts: 25
Hi,
Well u r right ,only u have to give the path till the directory i.e if ur class file suppose "abc.class" is in c/windows/anand directory,then set it to
set classpath=%classpath%;c:/windows/anand;
Let me know if u got it
Bye
Anand
anand rk
Greenhorn

Joined: Feb 07, 2001
Posts: 25
hey the class file is ur java class file which is created after u complie ur java file and not the jdbcodbc class file
clyde jones
Ranch Hand

Joined: Dec 02, 2000
Posts: 46
Anand,
Thanks for your help. I'm not sure if we're talking 'bout the same thing. Here's the situation. I am trying to create a MS Access database going through the ODBC Data Sourc Adminstrator. When I create a database with a 4.x format and then try to go and manually open the database to add a table, I get an "unrecognizable database format" message. If I use the 3.x or 2.x formats and use a can program from this book we are using in class, I get a "JAVA.SQL.Exception: No suitable Driver" message. I am using Access97 and win98. I really don't know wht's up. So far, everthing I've tried has failed. Once again, thanks for your help.
Clyde
Joe Paolangeli
Ranch Hand

Joined: Apr 05, 2000
Posts: 73
Have you tried creating the database inside the MSAccess environment before setting up the datasource? Also can you paste in the code you are using to get the connection?
clyde jones
Ranch Hand

Joined: Dec 02, 2000
Posts: 46
Joe,
Thanks for your willingness to help me. Yes I can make a database within Access(I made one named COREJAVA). Here is the code to connect to the database. Actually, It's code from a book we are using for class.
public static Connection getConnection()
throws SQLException, IOException
{ Properties props = new Properties();
String fileName = "ViewDB.properties";
FileInputStream in = new FileInputStream(fileName);
props.load(in);
String drivers = props.getProperty("jdbc.drivers");
if (drivers != null)
System.setProperty("jdbc.drivers", drivers);
String url = props.getProperty("jdbc.url");
String username = props.getProperty("jdbc.username");
String password = props.getProperty("jdbc.password");
return
DriverManager.getConnection(url, username, password);
}
Here is the code in the ViewDB.properties file:
jdbc.drivers=sun.jdbc.odbc.JdbcOdbcDriver
jdbc.url=Jdbc:Odbc:COREJAVA
jdbc.username=PUBLIC
jdbc.password=PUBLIC
Any suggestions would be appreciated.
Clyde
Joe Paolangeli
Ranch Hand

Joined: Apr 05, 2000
Posts: 73
I tried out your code an received the same error (No suitable driver). I fixed the error by removing a space at the end of the jdbc.drivers line in your property file. Give this a try and let me know the results.

long sun
Greenhorn

Joined: Feb 24, 2001
Posts: 18
I met the same problem ,can you explain clealy what is means remove a space at the end of jdbcdrivers line in property file.

Thank you.
Joe Paolangeli
Ranch Hand

Joined: Apr 05, 2000
Posts: 73
Assuming that the exact property data was pasted into Clyde's post, there is a space at the end of the jdbc.drivers line. When this value is retrieved from the property file the drivers variable is assigned the value of "sun.jdbc.odbc.JdbcOdbcDriver ". The extra space at the end causes the error. A solution to this problem is to delete the space at the end of the jdbc.drivers line in the property file. Another solution would be to use the trim() method.
For example:
String drivers = props.getProperty("jdbc.drivers").trim();
Hope this helps,
Joe
long sun
Greenhorn

Joined: Feb 24, 2001
Posts: 18
I try to use the way like you did,but it didn't make sense?
clyde jones
Ranch Hand

Joined: Dec 02, 2000
Posts: 46
Joe,
Thanks so much for your help. You were right. There was a space at the end of my jdbc.Drivers line. When I deleted it, and ran a ViewDB program, I got "[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified". Don't know what's up? Shouldn't the property file be saying it all. If you have any suggestions, I am all ears.
The jury is still out on whether or not I will drop this class, but you have given me confidence that I am on the right track and that I am not totally stupid. I don't think in a thousand years I would have figured out the space thing. Thanks for sharing your experience with me.
Clyde
Joe Paolangeli
Ranch Hand

Joined: Apr 05, 2000
Posts: 73
Yes, the space problem is not easy problem to uncover for a java newbie. I was able to uncover this problem because you pasted your exact property file into the post.
I can recreate your recent error by removing the datasource in the ODBC Data Source Administrator. Please check to see if your datasource named COREJAVA is still defined in the ODBC Data Source Administrator.
Good Luck,
Joe
clyde jones
Ranch Hand

Joined: Dec 02, 2000
Posts: 46
Joe,
I went back to the ODBC Source Administrator and the DSN was still there. I compacted it and tried to run the ViewDB program again. This time I got "Exception in thread "main" java.lang.NoClassDefFoundError: ViewDB". Is this telling me the program cannot find the JdbcOdbcDriver.class? If so, I wonder why because it is in the rt.jar file.
Thanks in Advance,
Clyde
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
It's telling you it can't find ViewDB.


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Joe Paolangeli
Ranch Hand

Joined: Apr 05, 2000
Posts: 73
As Thomas stated, java cannot find the ViewDB class. You need to make sure java can find this class by modifying the classpath. For example if ViewDB is located in a directory named "c:\javadev" then add this directory to the class path. Give it try and let me know about the results.
Also I discoverd yesterday that you can get a "No Suitable Driver" error if you misspell either the package or class name of the driver.
Good Luck,
Joe
clyde jones
Ranch Hand

Joined: Dec 02, 2000
Posts: 46
Joe,
I did as you and Thomas suggested and made a directory named java_Packages and put all the ViewDB classes in them. Didn't realize I needed to set a class path in my auto exec for using files that were under my jdk1.3 directory unless it was something outside of the java Platform. Now I am getting "[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified" again. I went back to the ODBC Source Adminstrator to see if the DSN was still there. It was. I repaired and compacted the database. I moved the properties and database files to the java_Packages directory. Still no success. I even opened the rt.jar file and extracted the path to the JdbcOdbcDriver.class in the java_Packages directory. Still no success. Here is my CLASSPATH line from my auto exec file:
"set CLASSPATH=C:\java_Packages;."
I also tried setting my classpath like this:
"set CLASSPATH=C:\java_Packages; ."

This spelling of the driver class name would be located in my properties file right? I feel like I'm so close, but I've should have been there days ago. Thanks for all your help.
Clyde
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
You need more than that in your classpath:
SET CLASSPATH=.;C:\Java\lib\classes.zip;C:\Java\lib;C:\java\lib\tools.jar;c:\java\lib\rt.jar;C:\java_Packages
clyde jones
Ranch Hand

Joined: Dec 02, 2000
Posts: 46
Thomas,
I set up my CLASSPATH as you suggested. After trying to run ("java ViewDB Authors") the program from C:\jdk1.3\msAccess,(This is where the DSN is looking for the database) and also trying to run the program from C:\java_packages (my CLASSPATH). I got the same "[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified" error. It's apparent that something is wrong with my paths, But I don't know what's up. My CLASSPATH is set, the DSN is set(maybe the database should be where my class files are) and my properties file appears to be in order. This is embarrassing.
Clyde
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Before you try to get a connection do you register the driver by doing this:
Class.forName(jdbc.drivers);
clyde jones
Ranch Hand

Joined: Dec 02, 2000
Posts: 46
Thomas,
No I am not using the forName(). I am using:
public static Connection getConnection()
throws SQLException, IOException
{ Properties props = new Properties();
String fileName = "ViewDB.properties";
FileInputStream in = new FileInputStream(fileName);
props.load(in);
String drivers = props.getProperty("jdbc.drivers");
if (drivers != null)
System.setProperty("jdbc.drivers", drivers);
String url = props.getProperty("jdbc.url");
String username = props.getProperty("jdbc.username");
String password = props.getProperty("jdbc.password");
return
DriverManager.getConnection(url, username, password);
}
This is what my properties file look like:
Here is the code in the ViewDB.properties file:
jdbc.drivers=sun.jdbc.odbc.JdbcOdbcDriver
jdbc.url=Jdbc:Odbc:COREJAVA
jdbc.username=PUBLIC
jdbc.password=PUBLIC
Is this not registering the driver?
Clyde
Joe Paolangeli
Ranch Hand

Joined: Apr 05, 2000
Posts: 73
You ever feel like you are in a endless loop ?
You don't need the "Class.forName(jdbc.drivers);" line because it seems that the "System.setProperty("jdbc.drivers", drivers);" registers your driver (I tried this out).
Your current error is caused by the datasource not being found (not a path error). The path to your database is specified in the ODBC Source Administrator. I can recreate the error if I place a space at the end of the jdbc.url line in your properties file, so check this first. Also are you sure that you are getting all of the values from your properties file? Did you use a debugger or System.out.println(); statements?
You are almost there,
Joe


clyde jones
Ranch Hand

Joined: Dec 02, 2000
Posts: 46
Joe,
Thanks for checking in on me. Honestly, I don't know how I feel. Although this is embarrasing, I'm not ready to give up. The last thread from me was for Thomas' benefit. I figured He hadn't read the thread about 10 or so threads back or maybe he just forgot about it. I checked my properties file for a space at the end of the url line and there wasn't one.
jdbc.drivers=sun.jdbc.odbc.JdbcOdbcDriver
jdbc.url=Jdbc:Odbc:COREJAVA
jdbc.username=PUBLIC
jdbc.password=PUBLIC
Yes I have been using System.out.println(); statements to see where I am breaking.
String drivers = props.getProperty("jdbc.drivers");
if (drivers != null)
System.setProperty("jdbc.drivers", drivers);
System.out.println(drivers);
String url = props.getProperty("jdbc.url");
System.out.println(url);
String username = props.getProperty("jdbc.username");
String password = props.getProperty("jdbc.password");
System.out.println(username);
System.out.println(password);
return
DriverManager.getConnection(url, username, password);
This is what I'm getting when I run the program.
C:\jdk1.3\msAccess>java ViewDB Authors
sun.jdbc.odbc.JdbcOdbcDriver
Jdbc:Odbc:COREJAVA
PUBLIC
PUBLIC

It appears I'm breaking at the DriverManager.getConnection(url, username, password). I've tried adding driver in front of url, but the program won't compile. I'm baffled at why I'm getting the error that I'm getting. You say I'm almost there. Man, I hope so. Does the database have to be in the same directory as the classes files? Right now, the ODBC Datasource Adminstrator is looking for the database in C:\jdk1.3\msAccess. My classes files are in C:\java_Packages.
Clyde
Joe Paolangeli
Ranch Hand

Joined: Apr 05, 2000
Posts: 73
Your database can remain in the same place. The path only needs to be specified in the ODBC Source Administrator. Also you should determine the exact line where the error is occuring. This can be done by placing System.out.println statements before and after retrieving the connection (the one after would need to be located in the calling method).
I am also baffled about the error at this point. I can get this method to work on my machine but I am using Windows 2000 and you are using Windows 98. Here are some additional things to try:
- Change "jdbc.url=Jdbc:Odbc:COREJAVA" to "jdbc.url=jdbcdbc:COREJAVA" in your properties file. I don't think this will make a difference but you never know. Also is your datasource name in uppercase?
- You may want to recreate your datasource in the ODBC Source Administrator.
- Also I was able to recreate a datasource not found error by adding a space at the end of the COREJAVA datasource name in the ODBC source administrator. Although, after doing this I was unable to reconfigure or remove the datasource (must be some MS bug).
good luck,
Joe

[This message has been edited by Joe Paolangeli (edited March 06, 2001).]
clyde jones
Ranch Hand

Joined: Dec 02, 2000
Posts: 46
Joe,
Finally got the connection. Thanks for your question "Also is your datasource name in uppercase?". My datasource name was accessCoreJava and my database name was COREJAVA. From your question, I created a new DSN and named it COREJAVA and created a new database and named it COREJAVA. I was able to open the MSAccess DB and see the table I was looking for. Thanks for all of your help!!! Now it's on to working with a MySQL DB and doing a small jsp project.
Thanks for not giving up on me,
Clyde

Joe Paolangeli
Ranch Hand

Joined: Apr 05, 2000
Posts: 73
Great! I'm glad we were finally able to get this problem resolved . Good luck with the rest of the class.
Joe
 
jQuery in Action, 2nd edition
 
subject: jdbc-odbc bridge problem