• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Vickram Chakravarthy
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2577
11
C++ Linux Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jan Cumps
Bartender
Posts: 2577
11
C++ Linux Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
... And welcome to JavaRanch, Vickram!
 
Vickram Chakravarthy
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And I'm able to compile simple programs and run , those that doesnt involve com.intersys.... packages.
 
Jan Cumps
Bartender
Posts: 2577
11
C++ Linux Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic