JNDI连接池连接Oracle数据库
今天做了一个评论的小功能,要求用JNDI连接池连接Oracle数据库,以前只是测试了是否连接的上,现在没想到一个JNDI连接池连接Oracle数据库,纠结了好久,原来都是Oracle数据库的问题,这是过失。下面介绍一下JNDI连接池连接Oracle数据库。

<?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数据库的更多相关文章
- python - DBUtils 连接池减少oracle数据库的连接数
问题: 接到需求,告知项目的oracle连接次数过多,对系统造成太过大的负担,要求减少oracle数据库的连接次数 分析: 仔细分析代码以后,发现产生问题的原因,在于之前要求提升oracle监控的监控 ...
- Mybatis 搭配 阿里druid连接池 连接 oracle 或 mysql
DRUID介绍 DRUID是阿里巴巴开源平台上一个数据库连接池实现,它结合了C3P0.DBCP.PROXOOL等DB池的优点,同时加入了日志监控,可以很好的监控DB池连接和SQL的执行情况,可以说是针 ...
- Java java jdbc thin远程连接并操作Oracle数据库
JAVA jdbc thin远程连接并操作Oracle数据库 by:授客 QQ:1033553122 测试环境 数据库:linux 下Oracle_11g_R2 编码工具:Eclipse 编码平台:W ...
- python使用dbutils的PooledDB连接池,操作数据库
1.使用dbutils的PooledDB连接池,操作数据库. 这样就不需要每次执行sql后都关闭数据库连接,频繁的创建连接,消耗时间 2.如果是使用一个连接一直不关闭,多线程下,插入超长字符串到数据库 ...
- jdbc连接rac的oracle数据库
jdbc连接rac的oracle数据库需要配置所有racIP,如下: DB1 =(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(H ...
- node 连接MySQL及其分装, 连接池连接
const mysql = require('mysql') const config = require('./../../config/config.default') var connectio ...
- python通过连接池连接redis,操作redis队列
在每次使用redis都进行连接的话会拉低redis的效率,都知道redis是基于内存的数据库,效率贼高,所以每次进行连接比真正使用消耗的资源和时间还多.所以为了节省资源,减少多次连接损耗,连接池的作用 ...
- spring boot配置druid连接池连接mysql
Spring Boot 集成教程 Spring Boot 介绍 Spring Boot 开发环境搭建(Eclipse) Spring Boot Hello World (restful接口)例子 sp ...
- springboot使用druid连接池连接Oracle数据库的基本配置
#阿里连接池配置 #spring.datasource.druid.driver-class-name=oracle.jdbc.driver.OracleDriver #可配可不配,阿里的数据库连接池 ...
随机推荐
- 中国省市区地址三级联动插件---jQuery Distpicker
插件描述:distpicker是一款可以实现中国省市区地址三级联动jQuery插件.它使用简单,简单设置即可完成中国省市区地址联动效果. [官网]https://fengyuanchen.github ...
- EntityFramewordCore 2.2 DBFirst简单使用
如何用EF Core连接数据库并且生成实体类? 1.通过Nuget安装依赖 Install-package Microsoft.EntityFrameworkCore Install-package ...
- springCloud学习-服务消费者(Feign)
1.简介 Feign是一个声明式的伪Http客户端,它使得写Http客户端变得更简单.使用Feign,只需要创建一个接口并注解.它具有可插拔的注解特性,可使用Feign 注解和JAX-RS注解.Fei ...
- [Cypress] Interact with Hidden Elements in a Cypress Test
We often only show UI elements as a result of some user interaction. Cypress detects visibility and ...
- QT中使用高速排序
今天想到了用QT做一个高速排序.所以研究了一下. 由于用习惯了,C++的std::sort.就算是C的时候也用得是stdlib.h中的qsort. 手写板 手写板的快排事实上不难,仅仅是自从用C++打 ...
- Android使用GestureDetector实现手势滑动效果
直接看实例: package com.example.gesturedetector; import android.os.Bundle; import android.app.Activity; i ...
- 替换文件里的相关单词(一)之文件类型为txt
首先说一下详细的实现思路: 第一步:我们须要获取要改动文件的信息,我们能够通过文件的路径来获取文件的FileInputStream,即文件的输入流,然后调用InputStreamReader读取文件输 ...
- 《Qt on Android核心编程》前言:为什么写作本书
2008年.我開始在CSDN写技术博客. 在此之前,我的理想是写出受人待见的小说来.我也以前在网络论坛上笔耕不辍获得一些成绩,也以前发表过一些散文以及小说.而那一年,当我再次拾起笔来写东西时.却选择了 ...
- jQuery - 制作非缘勿扰页面特效
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 【Git学习笔记】用git pull取回远程仓库某个分支的更新,再与本地的指定分支自动merge【转】
本文转载自:http://blog.csdn.net/liuchunming033/article/details/45367629 git pull的作用是,从远程库中获取某个分支的更新,再与本地指 ...