Meta-inf folder -> context.xml
in this write the following code
--<-- ?xml version="1.0" encoding="UTF-8"? -->--
--<-- Context antiJARLocking="true" path="/search" -->--
--<-- !-- Default set of monitored resources -- -->--
--<-- WatchedResource -->-- WEB-INF/web.xml --<-- /WatchedResource -->--
--<-- !-- Uncomment this to disable session persistence across Tomcat restarts -- -->--
--<-- !--
--<-- Manager pathname="" / -->--
-- -->--
--<-- Resource auth="Container"
driverClassName="com.mysql.jdbc.Driver"
factory="org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory"
logAbandoned="true" maxActive="30"
maxIdle="10"
maxWait="1000"
name="jdbc/POS"
removeAbandoned="true"
removeAbandonedTimeout="60"
type="javax.sql.DataSource"
url="jdbc:mysql://localhost:3306/POC?autoReconnect=true"
username="root"
password="kmipl"/ -->--
--<-- /Context -->--
Note : replace all --<-- with '<' -->-- with '>'
______________________________________________________________
to get the connection from context.xml file just use the following method
public Connection dbConnectionCheck()
{
try
{
Context initContext = new InitialContext();
Context envContext = (Context)initContext.lookup("java:/comp/env");
DataSource ds = (DataSource)envContext.lookup("jdbc/POS");
connection = ds.getConnection();
}
catch(Exception e1)
{
System.out.println(e1);
}
return connection;
}
_______________________________________________________
by this we can change the database with out redeploying or rebuilding the war file.
No comments:
Post a Comment