1、
Configure Tomcat's conf/context.xml
<Resource name="jdbc/news"
auth="Container" type="javax.sql.DataSource" maxActive="100"
maxIdle="30" maxWait="10000" username="admin" password="54321"
driverClassName="oracle.jdbc.OracleDriver"
url="jdbc:oracle:thin:@localhost:1521:news"/>
Configure Tomcat's conf/context.xml
<Resource name="jdbc/news"
auth="Container" type="javax.sql.DataSource" maxActive="100"
maxIdle="30" maxWait="10000" username="root" password="54321"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://127.0.0.1:3306/news"/>
2. Use JNDI to get the connection object
//initialize the context
Context cxt=new InitialContext();
//Get the data source object associated with the logical name
DataSource ds=(DataSource)cxt.lookup("java:comp/env/jdbc/news");
Connection connection=ds.getConnection();