java.lang.ArrayIndexOutOfBoundsException:连接到Oracle 10g XE时

时间:2013-02-02 04:45:00

标签: jdbc oracle10g

您好我正在尝试使用JDBC建立与Oracle的连接。

我在Win 7 x86上运行Oracle 10g R2 XE,Eclipse Java EE Juno和Java SE v1.7。我在WebContent / WEB-INF / lib中包含了class.12.jar和ojdbc5.jar,因为之前使用ojdbc.jar,它在连接数据库时出错。所以我完全不确定要包含哪个驱动程序。

我的代码是:

    Connection conn = null;
    String driverName = "oracle.jdbc.OracleDriver";
    String url = "jdbc:oracle:thin:@localhost:1521:xe";

    Class.forName(driverName);
    conn = DriverManager.getConnection(url, "system", "mypassword"); //exception occurs here

在最后一行提供以下例外

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(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at ConnectionManager.getConnection(ConnectionManager.java:16)
at ConnectionManager.main(ConnectionManager.java:24)

Sam做错了什么,或者我还在使用错误的驱动程序。我应该包括哪一个?

修改

我也尝试过网址:

String url = "jdbc:oracle:thin:@//localhost:1521/xe";

它给了我以下例外:

java.sql.SQLException: Io exception: Invalid connection string format, a valid format is: "host:port:sid" 
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:168)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:210)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:323)
at oracle.jdbc.driver.OracleConnection.<init>(OracleConnection.java:260)
at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.java:365)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:260)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at ConnectionManager.getConnection(ConnectionManager.java:17)
at ConnectionManager.main(ConnectionManager.java:25)

我也尝试将驱动程序名称更改为:

String driverName = "oracle.jdbc.driver.OracleDriver";

没用。

并且同时使用ojdbc5.jar,ojdbc6.jar,但没有用。 :'(

1 个答案:

答案 0 :(得分:0)

您的网址似乎有误。

您指的是ojdbc5.jar,最好使用ojdbc6.jar

Jar可以在这个位置找到: -

$ORACLE_HOME/jdbc/lib/ojdbc6.jar

这样做: -

Connection conn = null;
String driverName = "oracle.jdbc.driver.OracleDriver";

OR

String driverName = "oracle.jdbc.OracleDriver";
String url = "jdbc:oracle:thin:@//localhost:1521/xe";

Class.forName(driverName);
conn = DriverManager.getConnection(url, "system", "mypassword");