学习eclipse的安装的步骤
步骤一:
找到电脑上的Tomcat安装路径,找到lib文件夹,将数据库的jar包拷贝进去
注意:该Tomcat必须是与导入eclipse中的是同一个
步骤二:
打开eclipse,找到Servers项目,打开项目,找到context.xml文件,在当中配置如下:
<Resource
name="jdbc/sqlserver"
type="javax.sql.DataSource"
auth="Container"
driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver"
url="jdbc:sqlserver://localhost:1433;DatabaseName=tongxun"
username="sa"
password="111"
initialSize="10"
minldle="10"
maxActive="10"
maxWait="10000"
/>
步骤三:
在需要使用连接池的项目中找到web.xml文件,在文件中配置如下:
<resource-ref>
<res-ref-name>jdbc/sqlserver</res-ref-name>
<res-type>kavax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<resource-ref>
步骤四:
新建工具类获取数据库连接
public static Connection getcon() {
Connection co=null;
try{
Context ct=new InitialContext();
DataSource dt=(DataSource)ct.lookup("java:/comp/env/jdbc/sqlserver");
co=dt.getConnection();
}catch(Exception e){
e.printStackTrace();
}
return co;
}