Posted on 2006-10-09 01:05
chinaorg 阅读(168)
评论(0) 编辑 收藏 所属分类:
JAVA/JSP
server.xml
<Context path="/bookstore" docBase="bookstore" debug="0" reloadable="true">
<Resource name="jdbc/BookDB" auth="Container" type="javax.sql.DataSource" driverClassName="com.mysql.jdbc.Driver" maxActive="100" maxIdle="30" maxWait="10000" url="jdbc:mysql://localhost:3306/bookdb?autoReconnect=true" username="dbuser" password="1234" removeAbandoned="true"/>
</Context>
|
web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app> <welcome-file-list> <welcome-file>Dbjsp1.jsp</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <resource-ref> <description>DB connection</description> <res-ref-name>jdbc/BookDB</res-ref-name> <res-type>javax.sql.Datasource</res-type> <res-auth>Container</res-auth> <res-sharing-scope>Shareable</res-sharing-scope> </resource-ref> </web-app>
|
//数据库连接代码
Connection con; Statement stmt; ResultSet rs; Context ctx=new InitialContext(); DataSource ds=(DataSource)ctx.lookup("java:comp/env/jdbc/BookDB"); con=ds.getConnection(); stmt=con.createStatement();
|