zoukankan      html  css  js  c++  java
  • Tomcat8 配置Oracle11g数据源

    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);
            }
            
        }
    

      

     

  • 相关阅读:
    asp.net web生命周期
    图的数据结构1
    最长公共子串
    内部排序

    棋盘覆盖问题
    队列
    矩阵连乘问题
    图的数据结构2
    旅行售货员问题
  • 原文地址:https://www.cnblogs.com/yshyee/p/5657406.html
Copyright © 2011-2022 走看看