java.sql.SQLException:访问数据库时连接URL错误

时间:2014-12-23 12:21:34

标签: java jdbc ibm-midrange db2-400

我正在我的一个spring配置文件中配置数据库详细信息,如下所示:

<bean id="awd" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="com.ibm.as400.access.AS400JDBCDriver"/>
        <property name="url" value="jdbc:db2://123.43.133.257/XYZ" />
        <property name="username" value="xyz" />
        <property name="password" value="xyz" />
    </bean>

当我尝试从Java端连接上述数据库时,我收到以下异常:

Caused by: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: Bad connection URL
    at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:80)
    at org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.java:280)
    ... 139 more
Caused by: java.sql.SQLException: Bad connection URL
    at com.ibm.u2.jdbc.UniJDBCMsgFactory.createException(UniJDBCMsgFactory.java:109)
    at com.ibm.u2.jdbc.UniJDBCDriver.connect(UniJDBCDriver.java:116)
    at java.sql.DriverManager.getConnection(DriverManager.java:582)
    at java.sql.DriverManager.getConnection(DriverManager.java:154)
    at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriverManager(DriverManagerDataSource.java:173)
    at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriver(DriverManagerDataSource.java:164)
    at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnectionFromDriver(AbstractDriverBasedDataSource.java:153)
    at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnection(AbstractDriverBasedDataSource.java:119)
    at org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource.getConnection(AbstractRoutingDataSource.java:162)
    at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111)
    at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77)
    ... 140 more

有人可以告诉我这里有什么问题吗?

1 个答案:

答案 0 :(得分:2)

您使用的是AS400JDBCDriver,因此您的jdbc网址应该是这样的:

jdbc:as400://123.43.133.257/XYZ

而不是

jdbc:db2://123.43.133.257/XYZ