<Context> <Resource name="jdbc/<span style="font-family:simsun;">drp</span>" auth="Container" type="javax.sql.DataSource" maxActive="20" maxIdel="10" maxWait="1000" username="root" password="" driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://127.0.0.1:3306/test" > </Resource> </Context>
<resource-ref> <res-ref-name>jdbc/drp </res-ref-name> <res-type>javax.sql.DataSource </res-type> <res-auth>Container</res-auth> </resource-ref>
public static Connection getConnection(){ Connection conn = null; PreparedStatement pstmt=null; ResultSet set = null; try{ Context ctx=new InitialContext(); //通过JNDI查找DataSource DataSource ds=(DataSource)ctx.lookup("java:comp/env/jdbc/drp"); conn = ds.getConnection(); }catch(ApplicationException e){ e.printStackTrace(); } return conn; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文:http://blog.csdn.net/u010927139/article/details/47655091