Подключите DB2 с помощью Struts, Spring и Hibernate - PullRequest
0 голосов
/ 07 апреля 2011

Я объединяю стойки, пружину и Hibetnate вместе.Когда я пытался подключиться к DB2:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

<bean class="org.apache.commons.dbcp.BasicDataSource" id ="myDataSource" destroy-method="close">

        <property name="driverClassName" value="com.ibm.db2.jcc.DB2SimpleDataSource"/>
        <property name="url" value ="jdbc:db2://localhost:50000/MYTESTDB"/>
        <property name="username" value="db2admin"/>
        <property name="password" value="db2admin"/>        
</bean>

<bean id ="mySessionFactory" class= "org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource" ref="myDataSource"/>
    <property name="mappingResources">
        <list>
            <value>/com/tuanhuy/dao/UserBean.hbm.xml</value>
        </list>
    </property>

    <property name="hibernateProperties">               
        <value>hibernate.dialect=org.hibernate.dialect.DB2Dialect</value>       
    </property>
</bean>

Есть ошибки

javax.servlet.ServletException: org.hibernate.exception.GenericJDBCException: Cannot open connection
    org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:286)
    org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
    org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


原因 

org.hibernate.exception.GenericJDBCException: Cannot open connection
    org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:126)
    org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:114)
    org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
    org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:52)
    org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:449)
    org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:167)
    org.hibernate.jdbc.BorrowedConnectionProxy.invoke(BorrowedConnectionProxy.java:74)
    $Proxy4.createStatement(Unknown Source)
    com.tuanhuy.dao.UserDAOImpl.checkUserLogin(UserDAOImpl.java:34)
    com.tuanhuy.service.UserService.checkUserLogin(UserService.java:23)
    com.tuanhuy.struts.LoginAction.execute(LoginAction.java:32)
    org.apache.struts.chain.commands.servlet.ExecuteAction.execute(ExecuteAction.java:58)
    org.apache.struts.chain.commands.AbstractExecuteAction.execute(AbstractExecuteAction.java:67)
    org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
    org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
    org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:304)
    org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
    org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
    org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
    org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


原因 

org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (DB2 SQL Error: SQLCODE=-1031, SQLSTATE=58031, SQLERRMC=null, DRIVER=3.57.82)
    org.apache.commons.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1549)
    org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1388)
    org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
    org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider.getConnection(LocalDataSourceConnectionProvider.java:81)
    org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:446)
    org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:167)
    org.hibernate.jdbc.BorrowedConnectionProxy.invoke(BorrowedConnectionProxy.java:74)
    $Proxy4.createStatement(Unknown Source)
    com.tuanhuy.dao.UserDAOImpl.checkUserLogin(UserDAOImpl.java:34)
    com.tuanhuy.service.UserService.checkUserLogin(UserService.java:23)
    com.tuanhuy.struts.LoginAction.execute(LoginAction.java:32)
    org.apache.struts.chain.commands.servlet.ExecuteAction.execute(ExecuteAction.java:58)
    org.apache.struts.chain.commands.AbstractExecuteAction.execute(AbstractExecuteAction.java:67)
    org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
    org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
    org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:304)
    org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
    org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
    org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
    org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


原因 

com.ibm.db2.jcc.am.SqlException: DB2 SQL Error: SQLCODE=-1031, SQLSTATE=58031, SQLERRMC=null, DRIVER=3.57.82
    com.ibm.db2.jcc.am.bd.a(bd.java:679)
    com.ibm.db2.jcc.am.bd.a(bd.java:60)
    com.ibm.db2.jcc.am.bd.a(bd.java:127)
    com.ibm.db2.jcc.am.jb.a(jb.java:4191)
    com.ibm.db2.jcc.t4.bb.q(bb.java:697)
    com.ibm.db2.jcc.t4.bb.n(bb.java:525)
    com.ibm.db2.jcc.t4.bb.a(bb.java:329)
    com.ibm.db2.jcc.t4.bb.a(bb.java:112)
    com.ibm.db2.jcc.t4.b.m(b.java:1241)
    com.ibm.db2.jcc.t4.b.b(b.java:1114)
    com.ibm.db2.jcc.t4.b.c(b.java:701)
    com.ibm.db2.jcc.t4.b.b(b.java:687)
    com.ibm.db2.jcc.t4.b.a(b.java:374)
    com.ibm.db2.jcc.t4.b.<init>(b.java:310)
    com.ibm.db2.jcc.DB2SimpleDataSource.getConnection(DB2SimpleDataSource.java:214)
    com.ibm.db2.jcc.DB2Driver.connect(DB2Driver.java:224)
    org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38)
    org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:582)
    org.apache.commons.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:1556)
    org.apache.commons.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1545)
    org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1388)
    org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
    org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider.getConnection(LocalDataSourceConnectionProvider.java:81)
    org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:446)
    org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:167)
    org.hibernate.jdbc.BorrowedConnectionProxy.invoke(BorrowedConnectionProxy.java:74)
    $Proxy4.createStatement(Unknown Source)
    com.tuanhuy.dao.UserDAOImpl.checkUserLogin(UserDAOImpl.java:34)
    com.tuanhuy.service.UserService.checkUserLogin(UserService.java:23)
    com.tuanhuy.struts.LoginAction.execute(LoginAction.java:32)
    org.apache.struts.chain.commands.servlet.ExecuteAction.execute(ExecuteAction.java:58)
    org.apache.struts.chain.commands.AbstractExecuteAction.execute(AbstractExecuteAction.java:67)
    org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
    org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
    org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:304)
    org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
    org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
    org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
    org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

Ответы [ 2 ]

0 голосов
/ 21 апреля 2011

Почему вы используете driverClassName com.ibm.db2.jcc.DB2SimpleDataSource вместо com.ibm.db2.jcc.DB2Driver?

0 голосов
/ 07 апреля 2011

SQLCODE=-1031, SQLSTATE=58031 указывает, что каталог базы данных не может быть найден в файловой системе сервера базы данных.

См. документацию IBM по этой ошибке для получения дополнительной информации.

...