oracle tomcat配置

u012493548 2018-10-12 04:07:03
修改../conf/content.xml <?xml version='1.0' encoding='utf-8'?> <!-- 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/oracle" auth="Container" type="javax.sql.DataSource" driverClassName="oracle.jdbc.OracleDriver" url="jdbc:oracle:thin:@IP:1521:orcl" username="username" password="password" maxActive="5" maxIdle="2" maxWait="10000" /> </Context> 并将ojdbc6.jar拷贝到tomcat的lib目录下,以上则配置好了Oracle数据源。 在使用时需要在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_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>hpms</display-name> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list>   <!-- 在web.xml中加入如下内容 --> <resource-ref> <description>Java JDBC</description> <res-ref-name>jdbc/oracle</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref> </web-app> 实例: index.jsp 按 Ctrl+C 复制代码 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%@ page import="java.sql.*,javax.sql.*,javax.naming.*"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>My JSP 'tomcatTest.jsp' starting page</title> </head> <body> <% Context ctx = new InitialContext(); DataSource ds = (DataSource) ctx .lookup("java:comp/env/jdbc/oracle"); Connection con = ds.getConnection(); Statement st = con.createStatement(); ResultSet rs = st.executeQuery("select * from VENDORCLASS"); while (rs.next()) { out.println("<h1>" + rs.getString(2) + "</h1>"); } rs.close(); st.close(); con.close(); %> </body> 按 Ctrl+C 复制代码 浏览器访问: 转载请注明出处,谢谢
...全文
238 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
Rotel-刘志东 2018-10-13
  • 打赏
  • 举报
回复
没有看明白!!!!
卖水果的net 2018-10-12
  • 打赏
  • 举报
回复
楼主这是要做什么呢 ?

17,377

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧