注意 我正在运行Windows,路径看起来像是linus,因为我手动输入它,这就是我对路径的看法.
我正在尝试运行一个java类我已经构建来诊断我与数据库的连接,它引用了oracle jdbc适配器.
当我在没有类路径的情况下运行它时:
%> java DBDiagnostics
当它到达以下代码行时我得到一个异常:
Class.forName("oracle.jdbc.pool.OracleDataSource").newInstance();
除以下异常:
java.lang.ClassNotFoundException: oracle.jdbc.pool.OracleDataSource at java.net.URLClassLoader$1.run(URLClassLoader.java:200) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:188) at java.lang.ClassLoader.loadClass(ClassLoader.java:307) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:252) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:169) at DBDiagnostics.GetConnection(DBDiagnostics.java:43) at DBDiagnostics.runDiagnostic(DBDiagnostics.java:29) at DBDiagnostics.main(DBDiagnostics.java:18) Creating connection. java.sql.SQLException: No suitable driver found for lskd at java.sql.DriverManager.getConnection(DriverManager.java:602) at java.sql.DriverManager.getConnection(DriverManager.java:207) at DBDiagnostics.GetConnection(DBDiagnostics.java:55) at DBDiagnostics.runDiagnostic(DBDiagnostics.java:29) at DBDiagnostics.main(DBDiagnostics.java:18) Veryfying connectivity to Database Exception in thread "main" java.lang.NullPointerException at DBDiagnostics.verifyTable(DBDiagnostics.java:86) at DBDiagnostics.verifyTable(DBDiagnostics.java:76) at DBDiagnostics.verifyDatabseConnectivity(DBDiagnostics.java:68) at DBDiagnostics.runDiagnostic(DBDiagnostics.java:36) at DBDiagnostics.main(DBDiagnostics.java:18)
我认为这是因为我需要将它包含在类路径中.
所以,我尝试将它添加到类路径中,如下所示:
%> java -classpath .:ojdbc6.jar DBDiagnostics
VM只是说它找不到这个类:
Exception in thread "main" java.lang.NoClassDefFoundError: DBDiagnostics Caused by: java.lang.ClassNotFoundException: DBDiagnostics at java.net.URLClassLoader$1.run(URLClassLoader.java:200) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:188) at java.lang.ClassLoader.loadClass(ClassLoader.java:307) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:252) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320) Could not find the main class: DBDiagnostics. Program will exit.
我知道这是一个我应该知道答案的问题,但我做错了什么?
用分号替换冒号:
java -classpath .;ojdbc6.jar DBDiagnostics