-------- Oracle JDBC Connection Testing ------
Oracle JDBC Driver Registered!
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 7
at oracle.security.o3logon.C0.r(C0)
at oracle.security.o3logon.C0.l(C0)
at oracle.security.o3logon.C1.c(C1)
at oracle.security.o3logon.O3LoginClientHelper.getEPasswd(O3LoginClientHelper)
at oracle.jdbc.ttc7.O3log.<init>(O3log.java:289)
at oracle.jdbc.ttc7.TTC7Protocol.logon(TTC7Protocol.java:251)
at oracle.jdbc.driver.OracleConnection.<init>(OracleConnection.java:246)
at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.java:365)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:260)
at java.sql.DriverManager.getConnection(DriverManager.java:571)
at java.sql.DriverManager.getConnection(DriverManager.java:215)
at OracleJDBC.main(OracleJDBC.java:29)
代码: import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException;
public class OracleJDBC {
public static void main(String[] argv) {
System.out.println("-------- Oracle JDBC Connection Testing ------");
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
} catch (ClassNotFoundException e) {
System.out.println("Where is your Oracle JDBC Driver?");
e.printStackTrace();
return;
}
System.out.println("Oracle JDBC Driver Registered!");
Connection connection = null;
try {
connection = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "system","appdb");
} catch (SQLException e) {
System.out.println("Connection Failed! Check output console");
e.printStackTrace();
return;
}
if (connection != null) {
System.out.println("You made it, take control your database now!");
} else {
System.out.println("Failed to make connection!");
}
}
}
导致异常:&#34; ArrayIndexOutOfBoundsException&#34; 使用Oracle 11g XE&amp;将classes12.jar和ojdc14.jar添加到库中。
答案 0 :(得分:0)
当您使用不同于您应该使用的数据库驱动程序时,会发生这种情况。
您正在使用Jdbc版本9.x.在使用JDK 1.4而不是classes12.jar时,使用10.x连接到XE并使用ojdbc14.jar。 classes12.jar通常用于JDK 1.2&amp; JDK 1.3。
有关详情,请参阅here