JSP connects to the DB2 database in JBOSS

Source: Internet
Author: User

1. Unzip and install the Jboss container and start it. Access http: // localhost: 8080/jmx-console. If it is displayed as normal, the Jboss container is successfully started.

2. If Jboss is installed in the root directory of the D Drive, enter D:/jboss/server/default/deploy and create test. war directory, because the web application needs to be deployed on Jboss for access, this is actually a simulation of the Jboss web application deployment process to generate a war package, in test. the war directory according to the jsp web application structure to establish the corresponding WEB-INF directory, establish the test file index. jsp

<% @ Page contentType = "text/html; charset = gb2312" %> <% @ page import = "java. SQL. * "%> <% @ page import =" javax. SQL. dataSource "%> <% @ page import =" javax. naming. * "%> 

This is handled by connecting to the Jboss data source. RegionManager is the JDNI Name of JBoss. The Jboss data source configuration will be described later.

3. Assume that the sample database sample of DB2 has been installed on the local machine and the JBoss version is 3.2.3. Enter the D:/jboss/docs/examples/jca directory, copy db2-ds.xml to D:/jboss/server/default/deploy and edit

<datasources>  <local-tx-datasource>    <jndi-name>mycell</jndi-name>    <connection-url>jdbc:db2:sample</connection-url>    <driver-class>COM.ibm.db2.jdbc.app.DB2Driver</driver-class>    <user-name>db2admin</user-name>    <password>asiainfo</password>    <min-pool-size>0</min-pool-size>  </local-tx-datasource></datasources>

4. Ensure that the DB2 JDBC driver has been placed in the lib directory of the web application, restart JBoss, and access http: // localhost: 8080/test/index. jsp

Good luck

Note: When I start Jboss in the eclipse IDE environment and access the page with the DB2 database connection, the error no db2jdbc in java is always reported. library. path. After a long time, I found that the JDBC connection type of DB2 is incorrect. The above is type2, and then I changed it to type3. below is the data source setting of type3.

<datasources>  <local-tx-datasource>    <jndi-name>RegionManager</jndi-name>    <connection-url>jdbc:db2:127.0.0.1:sample</connection-url>    <driver-class>COM.ibm.db2.jdbc.net.DB2Driver</driver-class>    <user-name>db2admin</user-name>    <password>asiainfo</password>    <min-pool-size>0</min-pool-size>  </local-tx-datasource></datasources>

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.