Why doesn’t Java seem to respect my classpath?

I have jt400 in my directory jar:

/path
    /jt400.jar
    /Test.java

Test. Java content:

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 compiled 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, at jt400 I have verified in jar:

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

However, when I uncomment the entry line, I get

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

So either I completely misunderstood Java's classpath and import mechanism, or I'm sure it doesn't respect the classpath I provided

How can I solve this problem? I can't find anything useful on Google or stack overflow, but I don't spend much time on Java, so I'm sure I did something wrong

Solution

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

You missed the colon. It should be:

String url = "jdbc:as400://myserver.domain.com;DSN=DB2;Uid=name;Pwd=password;";
//                      /\
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>