码迷,mamicode.com
首页 > 数据库 > 详细

Tomcat8 配置Oracle11g数据源

时间:2016-07-10 12:38:22      阅读:392      评论:0      收藏:0      [点我收藏+]

标签:

1:context.xml

<Resource
		name="jdbcoracle"  
		auth="Container"
		type="javax.sql.DataSource"
		factory="org.apache.tomcat.dbcp.dbcp2.BasicDataSourceFactory"
		maxActive="20"
		maxIdle="1"
		maxWait="100"
		username="yshy"
		password="yshy"
		driverClassName="oracle.jdbc.OracleDriver"
		url="jdbc:oracle:thin:@localhost:1521:XE"/>

2:web.xml

<resource-ref>
        <description>Oracle 数据库连接池</description>
        <res-ref-name>jdbcoracle</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
    </resource-ref>

3:TestServlet.java

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        
        try {
            InitialContext  ctx = new InitialContext();
            DataSource ds = (DataSource) ctx.lookup("java:comp/env/jdbcoracle");
            Connection conn = ds.getConnection();
            out.print("数据源测试联接成功:"+conn);
        } catch (NamingException | SQLException ex) {
            Logger.getLogger(TestServlet.class.getName()).log(Level.SEVERE, null, ex);
        }
        
    }

  

 

 

Tomcat8 配置Oracle11g数据源

标签:

原文地址:http://www.cnblogs.com/yshyee/p/5657406.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!