婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁 > 知識庫 > 在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ù)庫驅動,加入到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)本文內容存在版權問題,煩請?zhí)峁┫嚓P信息告之我們,我們將及時溝通與處理。本站內容系統(tǒng)采集于網(wǎng)絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《在Tomcat服務器下使用連接池連接Oracle數(shù)據(jù)庫》相關的同類信息!
  • 本頁收集關于在Tomcat服務器下使用連接池連接Oracle數(shù)據(jù)庫的相關信息資訊供網(wǎng)民參考!
  • 推薦文章
    主站蜘蛛池模板: 藁城市| 南郑县| 岚皋县| 秀山| 平邑县| 萨迦县| 青河县| 越西县| 昆山市| 长子县| 乌拉特前旗| 景宁| 闽清县| 慈利县| 册亨县| 淄博市| 睢宁县| 邳州市| 徐水县| 清水河县| 牡丹江市| 龙胜| 尤溪县| 丹棱县| 蒙自县| 西丰县| 东乌珠穆沁旗| 黄大仙区| 石棉县| 衡南县| 七台河市| 古浪县| 乌兰察布市| 保靖县| 岑巩县| 楚雄市| 鹤山市| 大宁县| 湘乡市| 惠水县| 兰西县|