netbeans tomcat jt400链接数据库

时间:2015-04-02 15:55:21

标签: java tomcat netbeans jt400

首先对不起我的英语,这是我的第二语言。

我试图从websphere服务器迁移到tomcat 8服务器。 除了与数据库的连接外,每件事情都能正常工作。

据我所知,我在不同的地方查看我必须修改context.xml 但我一直得到这个日志形式tomcat:

第一部分在声明游泳池"

时转换为"问题

[BDD ERROR] Probl?me lors de la d?claration du pool:无法创建资源实例

这里是context.xml和我用来跟踪数据库的类。

    <?xml version="1.0" encoding="UTF-8"?>

<Context path="/CGR_Server" reloadable="true">
<Resource auth="Container"
name="java:comp/env/jdbc/OLA"
type="javax.sql.DataSource"
driverClassName="com.ibm.as400.access.AS400JDBCConnectionPoolDataSource"
url="jdbc:as400://OLA;naming=system;errors=full;"
username="XXXX"
password="XXXX"
maxIdle="10"
maxActive="200"
maxWait="5"
removeAbandoned="true"
removeAbandonedTimeout="1200"
/> 
</Context>  

连接到as400的方法

public boolean open(){
        DataSource source=null;                 
        try {

            source= (DataSource) new InitialContext().lookup(pools[as400]);
            connection = source.getConnection();


            if (connection == null){
                return false;
            }else{

                connection.setAutoCommit(autoCommit);
                if(scroll){
                    stmt=connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
                }else{
                    stmt=connection.createStatement();
                }
            }
        } catch (NamingException e) {
            traitementErreur(e);
            return false;               
        } catch (SQLException e) {
            traitementErreur(e);
            return false;           
        } catch (Exception e) {
            traitementErreur(e);
            return false;
        }

        return true;    
    }

1 个答案:

答案 0 :(得分:0)

We use Spring and Apache DBCP2 to configure the datasource. That way it is available for tests running in JUnit without starting Tomcat, and portable to other servers as well:

<bean id="db2DataSource" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close">
  <property name="driverClassName" value="com.ibm.as400.access.AS400JDBCDriver"/>
  <property name="url" value="${your.url}"/>
  <property name="username" value="${your.user}"/>
  <property name="password" value="${your.password}"/>
  <property name="connectionProperties" value="secure=${useSecureConnection};naming=system;block size=512;socket timeout=30000;date format=iso;prompt=false" />
  <property name="validationQuery" value="values 1"/>
  <property name="validationQueryTimeout" value="5"/>
</bean>

And then just inject the datasource into your class with Spring.