日期:2014-05-16 浏览次数:21027 次
<Resource
name="jdbc/project"
auth="Container"
type="javax.sql.DataSource"
driverClassName="com.mysql.jdbc.Driver"
maxIdle="30"
maxWait="5000"
username="root"
password="root"
url="jdbc:mysql://localhost:3306/project"
maxActive="100"/>
<Resource
name="jdbc/project"
auth="Container"
type="javax.sql.DataSource"
driverClassName="com.mysql.jdbc.Driver"
maxIdle="30"
maxWait="5000"
username="root"
password="root"
url="jdbc:mysql://localhost:3306/project"
maxActive="100"/>
public class DbConn {
Connection conn = null;
DataSource ds = null;
Context ctx = null;
String jndi_str = "java:comp/env/jdbc/project"; //tomcat数据源的JNDI
public Connection getConnection() {
try{
ctx = new InitialContext();
ds = (DataSource)ctx.lookup(jndi_str);
conn = ds.getConnection();
}catch(Exception e){
e.printStackTrace();
}
return conn;
}
}