濮阳杆衣贸易有限公司

主頁 > 知識庫 > 在Tomcat服務器下使用連接池連接Oracle數(shù)據(jù)庫

在Tomcat服務器下使用連接池連接Oracle數(shù)據(jù)庫

熱門標簽:征服眼公司地圖標注 美圖秀秀地圖標注 征服者火車站地圖標注 word地圖標注方向 百度地圖標注素材 阿爾巴尼亞地圖標注app 開封智能外呼系統(tǒng)廠家 人工智能地圖標注自己能做嗎 外呼線路外顯本地號碼
下面介紹在Tomcat服務器下使用連接池來連接數(shù)據(jù)庫的操作

一:修改web.xml文件:
復制代碼 代碼如下:

?xml version="1.0" encoding="UTF-8"?>
web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
display-name>project/display-name>
welcome-file-list>
welcome-file>index.html/welcome-file>
welcome-file>index.htm/welcome-file>
welcome-file>index.jsp/welcome-file>
welcome-file>default.html/welcome-file>
welcome-file>default.htm/welcome-file>
welcome-file>default.jsp/welcome-file>
/welcome-file-list>

resource-ref>
description>DBConnection/description>
res-ref-name>siniteksirm/res-ref-name>
res-type>javax.sql.DataSource/res-type>
res-auth>Container/res-auth>
/resource-ref>
/web-app>

在web-app之間插入resource-ref>這段代碼。指定要是用的Resource名稱。

二:修改tomcat下的context.xml文件:

在Context標簽之間加入如下代碼。
復制代碼 代碼如下:

Resource name="siniteksirm" auth="Container"
type="javax.sql.DataSource"
driverClassName="oracle.jdbc.OracleDriver"
url="jdbc:oracle:thin:@192.168.1.196:1521:orcl"
username="paxt"
password="paxt"
maxActive="20"
maxIdle="10"
maxWait="-1"
testOnBorrow="true"
validationQuery="select 1 from dual"/>

三:選擇Oracle的數(shù)據(jù)庫驅(qū)動,加入到Tomcat的lib包中。本項目中為:Ojdbc14.jar.

四:提供一個jsp頁面:
復制代碼 代碼如下:

%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
%@ page import="javax.naming.Context" %>
%@ page import="javax.naming.InitialContext" %>
%@ page import="java.sql.*" %>
%@ page import="javax.sql.DataSource" %>
!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
html>
head>
meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
title>Insert title here/title>
/head>
body>
%
DataSource ds = null;
try{
Context context = new InitialContext();
ds = (DataSource)context.lookup("java:comp/env/siniteksirm");
Connection conn = ds.getConnection();
PreparedStatement pst = conn.prepareStatement("select * from sdc_fundbase where rownum = 2");
ResultSet rs = pst.executeQuery();
while(rs.next()){
out.println(rs.getString("fund4"));
out.println("br/>");
}
if(ds != null){
out.println("數(shù)據(jù)庫連接");
}
}catch(Exception e){
e.printStackTrace();
out.println("數(shù)據(jù)庫連接失敗");
}
%>
/body>
/html>

啟動Tomcat,這樣就可以訪問頁面。
您可能感興趣的文章:
  • tomcat何時寫回響應數(shù)據(jù)報的詳析
  • Nginx + Tomcat實現(xiàn)請求動態(tài)數(shù)據(jù)和請求靜態(tài)資源的分離詳解
  • 解決Linux下Tomcat向MySQL插入數(shù)據(jù)中文亂碼問題
  • 基于Tomcat 數(shù)據(jù)源的原理、配置、使用介紹
  • Android實現(xiàn)與Apache Tomcat服務器數(shù)據(jù)交互(MySql數(shù)據(jù)庫)
  • Tomcat 7-dbcp配置數(shù)據(jù)庫連接池詳解
  • 使用Post方式提交數(shù)據(jù)到Tomcat服務器的方法
  • 使用Get方式提交數(shù)據(jù)到Tomcat服務器的方法
  • Tomcatc3p0配置jnid數(shù)據(jù)源2種實現(xiàn)方法解析

標簽:泰安 孝感 海北 六安 酒泉 淮南 葫蘆島 宜春

巨人網(wǎng)絡通訊聲明:本文標題《在Tomcat服務器下使用連接池連接Oracle數(shù)據(jù)庫》,本文關鍵詞  在,Tomcat,服務器,下,使用,;如發(fā)現(xiàn)本文內(nèi)容存在版權問題,煩請?zhí)峁┫嚓P信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《在Tomcat服務器下使用連接池連接Oracle數(shù)據(jù)庫》相關的同類信息!
  • 本頁收集關于在Tomcat服務器下使用連接池連接Oracle數(shù)據(jù)庫的相關信息資訊供網(wǎng)民參考!
  • 推薦文章
    富蕴县| 民丰县| 安西县| 邹平县| 苍梧县| 合水县| 大悟县| 临邑县| 长白| 米泉市| 舟山市| 四子王旗| 开江县| 交口县| 安化县| 民乐县| 临西县| 西和县| 佳木斯市| 万源市| 雅江县| 固原市| 元氏县| 西华县| 灵台县| 石阡县| 那坡县| 锦屏县| 昭通市| 赤壁市| 惠来县| 电白县| 邻水| 房山区| 靖江市| 女性| 左贡县| 河曲县| 贡山| 启东市| 郧西县|