Wayne Werner
Wayne Werner

Reputation: 51817

Why doesn't Java seem to respect my classpath?

I have the jt400.jar in my directory:

/path
    /jt400.jar
    /Test.java

The contents of Test.java:

import java.sql.*;

//import com.ibm.as400.*;  // To be uncommented later
public class Test {
    public static void main(String[] args) throws Exception {
        String url = "jdbc:as400//myserver.domain.com;DSN=DB2;Uid=name;Pwd=password;";
        Connection conn = DriverManager.getConnection(url);
    }
}

I compile this:

 $ javac -cp jt400.jar Test.java

And try to run:

 $ java -cp jt400.jar Test.java

Which produces:

Exception in thread "main" java.sql.SQLException: No suitable driver found for jdbc:as400://myserver.domain.com;DSN=DB2;Uid=name;Pwd=password;
        at java.sql.DriverManager.getConnection(DriverManager.java:635)
        at java.sql.DriverManager.getConnection(DriverManager.java:213)
        at Killer.main(Test.java:8)

Now, inside jt400.jar I have verified:

$ jar -tf jt400.jar | grep class | grep AS400 | grep Driv
com/ibm/as400/access/AS400JDBCDriver.class

Yet, when I uncomment the import line, I get

Test.java:3: package com.ibm.as400 does not exist
import com.ibm.as400.*;

So either I completely misunderstand Java's classpath and import mechanism, or it sure seems like it's not respecting the classpath that I provide.

How can I solve this problem? I haven't been able to find anything useful on Google or Stackoverflow, but I don't spend much time in Java so I'm sure I'm doing something wrong.

Upvotes: 3

Views: 1197

Answers (1)

Anubian Noob
Anubian Noob

Reputation: 13596

String url = "jdbc:as400//myserver.domain.com;DSN=DB2;Uid=name;Pwd=password;";

You're missing a colon, it should be:

String url = "jdbc:as400://myserver.domain.com;DSN=DB2;Uid=name;Pwd=password;";
//                      /\

Upvotes: 7

Related Questions