0

I need to connect to a pervasive database for my java application.

In the code below, my try block will always throw a ClassNotFoundException

import java.sql.*;
public class TesterClass {

    public static void main(String[] args)
    {

        try 
         {
           Class.forName("com.pervasive.jdbc.v2.Driver");
         } 
         catch(Exception e) 
         {
           System.err.print("ClassNotFoundException: ");
           System.out.println(e.toString());
           System.err.println(e.getMessage());
         }

    }
}

I have already set up my CLASSPATH system variable to point to:

C:\PROGRA~2\Pervasive Software\PSQL\bin\pvjdbc2.jar;
C:\PROGRA~2\Pervasive Software\PSQL\bin\pvjdbc2x.jar;
C:\PROGRA~2\Pervasive Software\PSQL\bin\jpscs.jar

I have no problem connecting to the database with C# .NET (if that matters)

ForeverStudent
  • 2,487
  • 1
  • 14
  • 33
  • Try using a completely short path rather than a mixed short and long path. Something like "c:\Progra~2\Pervas~1\psql\bin". Also, what version of Pervasive are you using? If it's v12 (or possibly later version of v11), the files might be in an Actian directory rather than a Pervasive Software directory. – mirtheil Feb 04 '16 at 21:42
  • I tried using the short path but it did not work. I have confirmed the jars actually exist in the path I have specified. The driver is actually there. – ForeverStudent Feb 04 '16 at 21:56
  • So it throws the ClassNotFoundException error but what else does it show? What version of PSQL are you using? – mirtheil Feb 05 '16 at 03:01
  • it says: ClassNotFoundException: com.pervasive.jdbc.v2.Driver java.lang.ClassNotFoundException: com.pervasive.jdbc.v2.Driver. I am using PSQL10 – ForeverStudent Feb 05 '16 at 13:49
  • What version of java are you using? Both for compiling and running. – mirtheil Feb 05 '16 at 20:34
  • How are you running your program? A lot of ways of executing Java program will not use the `CLASSPATH` environment variable (and in most case you should avoid it). Side note: use `e.printStackTrace()` to print out an exception to standard error output; it is the format expected by most Java developers – Mark Rotteveel Feb 06 '16 at 12:07
  • typing `java -version` in the command prompt gives me 1.7.7_79 this version is compatible with my driver. I am able to compile and run the program successfully in the command prompt. This leads me to believe it might be an issue with my eclipse config – ForeverStudent Feb 08 '16 at 15:48
  • @MarkRotteveel I am trying to run in eclipse and it is not working, command prompt is working. – ForeverStudent Feb 08 '16 at 16:10
  • 1
    Then You need to add it to the build path of your eclipse project. – Mark Rotteveel Feb 08 '16 at 17:13
  • @MarkRotteveel I did that and it worked, but it is very annoying to have to add a bunch of seperate jars to every single project that are all included in CLASSPATH. I did not have to do this before. Is there another way? – ForeverStudent Feb 08 '16 at 17:16
  • It would be far more annoying if that wouldn't be necessary. Guess what happens if you share a project with others. Or if you need different versions of a library for different projects. – Mark Rotteveel Feb 08 '16 at 17:22
  • very true .However in my case, my `CLASSPATH` is relatively short and it contains jars that I am using for almost every project. In my past configuration (which I have lost), eclipse would use my `CLASSPATH` jars without me needing to explicitly include them in every project. I wonder what that configuration was – ForeverStudent Feb 08 '16 at 17:26
  • I believe there is an option to add the system class path to the build path in an eclipse project; I've never used it though. – Mark Rotteveel Feb 08 '16 at 21:18

0 Answers0