`
wdhdd889
  • 浏览: 150096 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

tomcat 中使用jdbc数据库连接次

阅读更多

1 将jdbc驱动类拷贝到tomcat的lib目录下

2 在tomcat 的server.xml文件中的<GlobalNamingResources>

   标签中添加如下内容

   <Resource

       name="jdbc/test"

 type="javax.sql.DataSource"

password=""

driverClassName="com.MySQL.jdbc.Driver"

maxIdle="40"

maxWait="50"

username=""

url=""

maxActive=""    

 />

3  在tomcat的context.xml中<Context>标签中添加如下内容

  <ResourceLink name="jdbc/test" global="jdbc/test" type="javax.sql.DataSource">

 

4 创建动态web 项目

5 修改web.xml文件内容 添加如下内容

 <resource-ref>

   <res-ref-name>jdbc/test</res-ref-name>

    <res-type>javax.sql.DataSource</res-type>

   <res-auth>Container</res-auth>

</resource-ref>

  6 编写连接的通用类

 String strPoolName="jdbc/test";//定义的连接次名字

      InitialContext ctx = new InitialContext()

DataSource ds = (DataSource)ctx.lookup("java:comp/env"+strPoolName);

Connection conn = ds.getConnection();

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics