1. Install the WebSphere for window version and start it in the service. Access http: // localhost: 9060/IBM/console. If it is normal, it indicates no problem.
2. Install db28.1 and create the sample library sample
3. Create a data source
- Select menu-> environment-> WebSphere variable, find the db2_jdbc_driver_path variable, and set the DB2 JDBC driver path. my options are C:/IBM/sqllib/Java/
- Choose> resource> JDBC provider to enter the DB2 legacy cli-based type 2 JDBC driver connection, enter the "Data Source" connection, and select new, set the name, JNDI name, and database name. The key is the JNDI name and database name. This is the key to connecting to the database. Remove the option "use this data source for container management persistence (CMP)", click the application, and select "J2EE Connector Architecture (j2c) certified data entry" and set relevant information, go back to the data source and select "authentication alias for Component Management"
- Test whether the data source connection is successful
4. If the data source is set successfully, deploy the applicationProgramBecause WebSphere needs to deploy the ear file, we can first create an shell J2EE application, such as regionmanager, for convenience. After the ear is successfully deployed, we can directly access C: /program files/IBM/WebSphere/appserver/profiles/nvirv01/installedapps/zhoucgnode01cell/regionmanager. ear/regionmanagerweb. the war directory is developed according to the normal Web application process.
5. On the test page, we can connect the data source. Suppose that the JNDI name is JDBC/db2_local, then the followingCodeWrite
Datasource DS = NULL; connection conn = NULL; Context CTX = new initialcontext (); DS = (datasource) CTX. lookup ("JDBC/db2_local"); Conn = Ds. getconnection (); statement stmt = Conn. createstatement ();