`
txazo
  • 浏览: 78522 次
  • 性别: Icon_minigender_1
  • 来自: 武汉
社区版块
存档分类
最新评论

Tomcat JDNI Datasource

阅读更多
1. TOMCAT_HOME/conf/context.xml的<Context>标签下添加如下内容:
<Resource name="jdbc/txazo" auth="Container" type="javax.sql.DataSource"
    maxActive="100" maxIdle="30" maxWait="10000"
    username="root" password="root"     
    driverClassName="com.mysql.jdbc.Driver"
    url="jdbc:mysql://localhost:3306/txazo"/>

2. WEB-INF/web.xml中添加如下内容:
<resource-ref>
    <res-ref-name>jdbc/txazo</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
</resource-ref>

3. Web应用中访问JNDI DataSource
InitialContext context = new InitialContext();
DataSource dataSource = (DataSource) context.
        lookup("java:comp/env/jdbc/txazo");
Connection connection = dataSource.getConnection();
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics