aspose file tools*
The moose likes JDBC and the fly likes Connecting with JDBC - ClassNotFoundException: com.intersys.jdbc.CacheDriver error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Connecting with JDBC - ClassNotFoundException: com.intersys.jdbc.CacheDriver error" Watch "Connecting with JDBC - ClassNotFoundException: com.intersys.jdbc.CacheDriver error" New topic
Author

Connecting with JDBC - ClassNotFoundException: com.intersys.jdbc.CacheDriver error

Vickram Chakravarthy
Greenhorn

Joined: May 05, 2010
Posts: 3
Hi,

I'm new to JDBC and trying to write a simple program to connect to Cache database. the program is pasted below.

import java.sql.*;
public class jdbc
{
public static void main(String args[])
{

String url="jdbc:Cache://localhost:1972/USER";
String username="_SYSTEM";
String password="SYS";
try
{
Class.forName ("com.intersys.jdbc.CacheDriver");
}
catch (java.lang.ClassNotFoundException e)
{
System.err.print("ClassNotFoundException: ");
System.err.print(e.getMessage());
return ;
}
try
{
Connection conn = DriverManager.getConnection(url, username, password);
}
catch(Exception e)
{
System.out.println("Crap");
}

}
}

Its compiling fine, but when I run it, it gives the error which I have specified in the subject line. I have included the CacheDB.jar file in the CLASSPATH of user variables, which is C:\InterSystems\Cache\Dev\java\lib\JDK14;, but still I get this error. Please help if anyone knows the cause.
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2510
    
  10

Its compiling fine, but when I run it, it gives the error which I have specified in the subject line. I have included the CacheDB.jar file in the CLASSPATH of user variables, which is C:\InterSystems\Cache\Dev\java\lib\JDK14;, but still I get this error. Please help if anyone knows the cause.

It is a classpath issue.
The jdbc driver is not needed for compilation. That is probably the reason why you don't get compilation errors.
However, you must have missed out something when you defined the classpath when you ran your program.
My advise is to read the Java tutorial on setting the correct classpath for your platform (Windows), and to retry once you have confirmed that you followed the steps.


OCUP UML fundamental and ITIL foundation
youtube channel
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2510
    
  10

... And welcome to JavaRanch, Vickram!
Vickram Chakravarthy
Greenhorn

Joined: May 05, 2010
Posts: 3
Hi,

Thanks for your reply, I'm getting a compilation error if I compile with import com.intersys.jdbc.CacheDriver;

I read in the cache documentation that the JDBC drivers for cache are present in the CacheDB.jar, so included that path in the classpath of user variables
C:\InterSystems\Cache\Dev\java\lib\JDK14 and also C:\InterSystems\Cache\Dev\java\lib\JDK15, my question is why do I still get this error?

When I view the cachedb.jar file using wordpad, I'm able to see these lines as well with some junk characters.

com/intersys/jdbc/PK

Appreciate your help.

Regards.
Vickram Chakravarthy
Greenhorn

Joined: May 05, 2010
Posts: 3
And I'm able to compile simple programs and run , those that doesnt involve com.intersys.... packages.
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2510
    
  10

You don't need to import that driver. You can see in jdbc tutorials that it is not neccessary to import the jdbc driver class.
Don't put "import com.intersys.jdbc.CacheDriver; " in your code.

And your classpath is still wrong. Fix it first.

The fact that your code compiles tells that it is valid java syntax.
The fact that it throws the ClassNotFoundException tells you that something is missing in your classpath.
That something is the jdbc driver for your database.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Connecting with JDBC - ClassNotFoundException: com.intersys.jdbc.CacheDriver error