JS in the JSP has two ways to implement, one is using Jndi (Java naming Directory Interface), which may be related to the application server, if it is resin, first in resin.conf definition
<resource-ref>
<res-ref-name>jdbc/oracle</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<init-param driver-name= "Oracle.jdbc.driver.OracleDriver"/>
<init-param url= "Jdbc:oracle:thin:@192.168.1.1:1521:oracle"/>
<init-param user= "System"/>
<init-param password= "Manager"/>
<init-param max-connections= "/>"
<init-param max-idle-time= "/>"
</resource-ref>
If Tomcat is defined in Server.xml, the relevant information can be found in the document and then used in the JSP
try{
Javax.naming.Context env = (context) new InitialContext (). Lookup ("java:comp/env");
Javax.sql.DataSource pool= (Javax.sql.DataSource) env.lookup ("jdbc/oracle");
}catch (Exception e) {System.err.println ("Exception Error:" +e.getmessage ());}
try {
Connection conn = Pool.getconnection ();
}catch (Exception e) {System.out.println ("Exception Error:" +e.getmessage ());}
With this code, you get a connection conn from the connection pool. If you want to use a common connection pool, that can only use JavaBean, first write a ConnectionPool Java class, and then directly from the connection pool to obtain the connection, the following is my one connection pool JavaBean
Connectionpool.java is as follows:
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.