SFD2008 in GuiZhou University Eddan

Thursday Apr 02, 2009

    After several days's research,I am success in configuring connection pool under Struct .The Web server i used is Glassfish V3 today.By the way ,the DataBase i choosed is MySQL.

    The steps is following:

    1、Put MySQL driver under \web\WEB-INF\lib .

    2、Configure JDBC

         In NetBeans,First,turn to Server page and right-click Glassfish , then choose "View Management Console ",and it will open automatically a web page where you can configure your JDBC.In addition ,before you configure JDBC ,pls assure you have start Glassfish V3,the operation let you enter Management Console page directly.However,if you don't start Glassfish first,you can enter username and password (admin/adminadmin) in  Management Console page .

         Eg.2.1、Configure Connection Pools

          name:testPool

         Datasource Classname:com.mysql.jdbc.jdbc2.optional.MysqlDataSource

         Resource Type:javax.sql.DataSource.

         .....some defualt configuration........

         in Additionanl Properties:

          databaseName;demo(which i have created in MySQL)

           portNumber:3306

           datasourceName:demoPool

            serverName:127.0.0.1

             password:******

            2.2、Configure JDBC Resource

            JNDI name:jdbc/demo

            Pool Name:choose "testPool" which is created in the prestep.

   3、Configure web.xml

          add <resource-ref>element into web.xml:

   <resource-ref>
        <res-ref-name>jdbc/demo</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
    </resource-ref>

        The Purpose is that program quotes JNDI resource in Web application.

   4、Configure structs-config.xml

        Add  datasource components into structs-config.xml:

    <data-sources>
       <data-source type="org.apache.commons.dbcp.BasicDataSource">
           <set-property property="driverClassName" value="org.gjt.mm.mysql.Driver" />
           <set-property property="url" value="jdbc:mysql://localhost:3306/demo" />
           <set-property property="username" value="root" />
           <set-property property="password" value="******" />
           <set-property property="maxActive" value="10" />
           <set-property property="maxWait" value="5000" />
           <set-property property="defaultAutoCommit" value="false" />
           <set-property property="defaultReadOnly" value="false" />
           <set-property property="validationQuery" value="SELECT COUNT(*) FROM user" />
       </data-source>
    </data-sources>

    5、write anther code you need ,enjoy~~~~~

    Thanks Mingwei Tang ~~

    Reference:

http://blog.csdn.net/zavens/archive/2008/07/06/2617094.aspx

http://yubook.blogspot.com/2009/03/glassfish.html

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed