JDBC DataSource Configuration in Tomcat

Put a file named context.xml in META-INF folder which contains: <?xml version=”1.0″ encoding=”UTF-8″?> <Context><Resource name=”MySQLDS” type=”javax.sql.DataSource” driverClassName=”com.mysql.jdbc.Driver” password=”root” maxIdle=”2″ maxWait=”5000″ username=”root” url=”jdbc:mysql://localhost:3306/test” maxActive=”10″/></Context> Getting the DataSource: Context context = new InitialContext();DataSource MYSQL_DATASOURCE = (DataSource) context.lookup(“java:comp/env/MySQLDS”);

Read More