I am using JNDI for database connection. I have created a XML file in META-INF for connection.
<?xml version="1.0" encoding="UTF-8"?>
<!-- The contents of this file will be loaded for each web application -->
<Context crossContext="true">
<!-- Default set of monitored resources -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<Resource name="jdbc/myDB" auth="Container"
type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="600000"
username="root"
password="abc123"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/game"/>
</Context>
In java class I am using following code to get the connection
Context envContext;
Datasource ds;
envContext = new InitialContext();
Context initContext = (Context)envContext.lookup("java:/comp/env");
DataSource ds = (DataSource)initContext.lookup("jdbc/myDB");
Connection con=ds.getConnection();
But, how can i close the connection?