Configure the connection pool in Tomcat
1. Open Server.xml: Add the following connection pool parameter statement in
/ value> parameter>
Import java.sql. *; import javax.sql. *; import javax.naming. *;
Public class oracledb {string URL_ = "192.168.1.41:1521:Gxcring"; // String URL_ = "172.18.51.101:1521:Sundb"; string id_ = "cms_user"; string pass_ = "12345";
CONNECTION conn = null; statement stmt = null;
Public OracleDb () {Try {//class.forname ("Oracle.jdbc.driver.Oracledriver"); // conn = drivermanager.getConnection ("JDBC: Oracle: Thin: @" URL_, ID_, Pass_); context INITCONText (); context envcontext = (context) INITCONTEXT.LOOKUP ("java: / comp / ENV"); DataSource DS = (DataSource) EnvContext.lookup ("JDBC / Waporacle"); // Note The name here The same is the same as the name in the configuration file. CONN = ds.getConnection ();
stmt = conn.createStatement (ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);} catch (NamingException ne) {System.out.println ( "Initial DataSource error."); ne.printStackTrace ();} catch (SQLException e) {System .out.println ("Oracle:" E); E.PrintStackTrace ();}} / ** * Return Connction Object * @Param None * @return CONNCTION * / PUBLIC Connection getConn () {Return this.conn;} }
Ha ha. This will be, there is nothing to use to use JDBC when calling the database elsewhere. Very simple.