1:context.xml
<resourcename= "Jdbcoracle" auth= "Container" type= "Javax.sql.DataSource" factory= " Org.apache.tomcat.dbcp.dbcp2.BasicDataSourceFactory "maxactive=" "maxidle=" 1 "maxwait=" username= "Yshy" Password= "Yshy" driverclassname= "Oracle.jdbc.OracleDriver" url= "Jdbc:oracle:thin: @localhost: 1521:xe"/>
2:web.xml
<resource-ref> <description>oracle database connection pool </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 ("Data source test Join succeeded:" +conn); } catch (Namingexception | SQLException ex) { Logger.getlogger (TestServlet.class.getName ()). log (Level.severe, NULL, ex); } }
TOMCAT8 Configuring ORACLE11G Data sources