我已将 mysql-connector-java-5.1.18-bin.jar 添加到 jre 和 jdk 库中。这是:
C:\Windows\system32>javap java.io.Bits
Compiled from "Bits.java"
class java.io.Bits extends java.lang.Object{
java.io.Bits();
static boolean getBoolean(byte[], int);
static char getChar(byte[], int);
static short getShort(byte[], int);
static int getInt(byte[], int);
static float getFloat(byte[], int);
static long getLong(byte[], int);
static double getDouble(byte[], int);
static void putBoolean(byte[], int, boolean);
static void putChar(byte[], int, char);
static void putShort(byte[], int, short);
static void putInt(byte[], int, int);
static void putFloat(byte[], int, float);
static void putLong(byte[], int, long);
static void putDouble(byte[], int, double);
}
C:\Windows\system32>javap com.mysql.jdbc.Driver
ERROR:Could not find com.mysql.jdbc.Driver
但是当我显示同一文件的直接类路径时,就可以了。
C:\Windows\system32>javap -classpath "B:\Java\Tools\mysql-connector-java-5.1.18\
mysql-connector-java-5.1.18\mysql-connector-java-5.1.18-bin.jar" com.mysql.jdbc.
Driver
Compiled from "Driver.java"
public class com.mysql.jdbc.Driver extends com.mysql.jdbc.NonRegisteringDriver i
mplements java.sql.Driver{
public com.mysql.jdbc.Driver() throws java.sql.SQLException;
static {};
}
当我使用时问题就开始了蒂洛的回答 https://stackoverflow.com/questions/1010919/adding-files-to-java-classpath-at-runtime动态加载驱动程序。没有 IOException。但在弦上Class.forName(driver).newInstance()
I have ClassNotFoundException
例外。将jar添加到jre后,没有任何变化。这有什么问题吗?