Showing posts with label CONFIGURING DATASOURCE IN TOMCAT 6. Show all posts
Showing posts with label CONFIGURING DATASOURCE IN TOMCAT 6. Show all posts

Wednesday, 31 October 2012

CONFIGURING DATASOURCE IN TOMCAT 6

//CONFIGURING DATASOURCE IN TOMCAT 6




STEP 1: Include the following Resource element inside GlobalNamingResources element in server.xml located in apache_tomcat_root/conf
<GlobalNamingResources>
……………………….
<Resource auth="Container" type="javax.sql.DataSource" driverClassName="com.ibm.db2.jcc.DB2Driver"                 url="jdbc:db2://localhost/ACETEST" name="jdbc/SAMPLETEST"     username="db2admin"     password="db2admin" />
…………………………….

  </GlobalNamingResources>
 //url={your database server url}
 //  name={your datasource  name} 
 //  username/password={your database username/password}

STEP 2: Include the following ResourceLink element inside Context element in context.xml located in apache_tomcat_root/conf
<Context>
………………….
<ResourceLink name="jdbc/SAMPLETEST" global="jdbc/SAMPLETEST" type="javax.sql.DataSource"/>
……………………
</Context>

STEP 3: Use the datasource to get the connection
 //code to access the datasource
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
DataSource ds = (DataSource) envCtx.lookup("jdbc/SAMPLETEST");
Connection c = ds.getConnection();


Custom single threaded java server

 package com.diffengine.csv; import java.io.*; import java.net.*; import java.util.Date; public class Server { public static void main(Str...