简体   繁体   中英

Java How To Find Class? (Attempting to load the driver: com.mysql.jdbc.Driver)

I am trying to use adit in my local environment.

I copied the files to:

/Users/koraytugay/adit-0.93

I go to terminal and type:

export CLASSPATH=$CLASSPATH:/Users/koraytugay/adit-0.93/mysql-connector-java-5.1.33.jar

I am sure that .jar file is there.

Then I type:

Korays-MacBook-Pro:adit-0.93 koraytugay$ java -jar adit.jar

However I am constantly getting:

Attempting to load the driver: com.mysql.jdbc.Driver
Driver not found
SQL Exeception: No suitable driver found for jdbc:mysql://localhost/ebtam

What am I doing wrong?

When you use -jar , the CLASSPATH environment variable is ignored.

The simplest approach here would probably be to use:

java -cp adit.jar:/Users/koraytugay/adit-0.93/mysql-connector-java-5.1.33.jar foo.bar.MyMainClass

Alternatively, you can specify relative classpath entries to a jar file via the manifest . So you could have:

Class-Path: mysql-connector-java-5.1.33.jar

in the manifest, and copy that jar file into the same directory as adit.jar , then you should be able to use -jar .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM