JNDI连接池连接Oracle数据库
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了JNDI连接池连接Oracle数据库,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3382字,纯文字阅读大概需要5分钟。
内容图文
![JNDI连接池连接Oracle数据库](/upload/InfoBanner/zyjiaocheng/448/f73eb68e12d34348a6d1e72607206dbc.jpg)
![JNDI连接池连接Oracle数据库 - 文章图片](/upload/getfiles/0001/2021/4/24/20210424093825734.jpg)
<?xml version=‘1.0‘ encoding=‘utf-8‘?> <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <!-- The contents of this file will be loaded for each web application --> <Context> <!-- Default set of monitored resources --> <WatchedResource>WEB-INF/web.xml</WatchedResource> <!-- Uncomment this to disable session persistence across Tomcat restarts --> <!-- <Manager pathname="" /> --> <!-- Uncomment this to enable Comet connection tacking (provides events on session expiration as well as webapp lifecycle) --> <!-- <Valve className="org.apache.catalina.valves.CometConnectionManagerValve" /> --> --红色字体是需要根据数据库名配置 <Resource name="jdbc/liuyan" auth="Container" type="javax.sql.DataSource" maxActive="100" maxIdle="30" maxWait="10000" username="epet" password="123456" driverClassName="oracle.jdbc.driver.OracleDriver" url="jdbc:oracle:thin:@localhost:1521:orcl" /> </Context>
import java.sql.Connection; import java.sql.SQLException; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; import javax.sql.DataSource; /** * 文件名:JNDI.java * 描 述:这是一个数据库连接类 * 作 者:WLX * 所属项目:MyNews * JDK版本:JDK1.7 * 创建时间:2015年5月23日 下午2:54:24 * */ public class JNDI { public Connection getconn() { Connection conn = null; try { Context ctx; ctx = new InitialContext(); //java:comp/env/为前缀 DataSource source = (DataSource)ctx.lookup("java:comp/env/jdbc/liuyan"); Connection connection = source.getConnection(); if(connection != null){ conn = connection; } } catch (NamingException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } return conn; } }
JNDI连接池连接Oracle数据库
标签:
本文系统来源:http://www.cnblogs.com/wlx520/p/4524861.html
内容总结
以上是互联网集市为您收集整理的JNDI连接池连接Oracle数据库全部内容,希望文章能够帮你解决JNDI连接池连接Oracle数据库所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。