MySQL连接器类路径

时间:2013-01-16 17:11:45

标签: java mysql linux jdbc

我的$ CLASSPATH技能不是很好,我在设置mysql-connector以使用我的MySQLAccess类时遇到了麻烦。我编译并将MySQLAccess类放在与my-sql-connector.jar相同的目录中。这是我的代码:

java -classpath :/home/rick/Downloads/mysql-connector-java-5.1.22/mysql-connector-java-5.1.22-bin.jar MySQLAccess

Exception in thread "main" java.lang.NoClassDefFoundError: MySQLAccess
Caused by: java.lang.ClassNotFoundException: MySQLAccess
    at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: MySQLAccess. Program will exit.

1 个答案:

答案 0 :(得分:2)

添加一个.表示当前位置

java -classpath /home/rick/Downloads/mysql-connector-java-5.1.22/mysql-connector-java-5.1.22-bin.jar:. MySQLAccess