import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
/*
连接池配置过程:
1.Tomcat 6.0\conf\context.xml
<Resource name="jdbc/db_G309" auth="Container" type="javax.sql.DataSource"
maxActive="50" maxIdle="30" maxWait="10000" logAbandoned="true"
username="sa"
password="xiao7520"
driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver"
url="jdbc:sqlserver://127.0.0.1:1433;databasename=db_G309"/>
2.Tomcat 6.0\webapps\G309\WEB-INF\web.xml 在<web-app></web-app>之间添加:
<resource-ref>
<description>MyProject_G309_DBPool</description>
<res-ref-name>jdbc/db_G309</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
3.调用的代码:
public Connection getConnection() throws SQLException {
try {
Context ctx = new InitialContext();
本内容试读结束,登录后可阅读更多
下载后可阅读完整内容,剩余2页未读,立即下载