I spent me a night, I finally solved the Tomcat connection pool. 5555555 Connection pool I have a new practice code in editing JSP with Eclipse, calling the Oracle process (through the Tomcat connection pool) ------------------------------------------------------- ----------------------------------ready:
1. Oracle9i, build a table in the HS user to put two fields in the TRY table in the TRY table.
2. Of course, you have to open OracleoraHome92TnsListener and Oracleserviceshaird (---- Shaird is my database name).
3. Put the required driver into the system variable classpath; Oracle is Classes12.jar in the LIB file in the Oracle installation directory. Note Yes .jar. You can also put this file in Tomcat / Common / Lib.
4. My classpath =.; E: /SUN /APPSERVER/JDK/LIB/Tools.jar; e: /oracle/ora92/jdbc/lib/classes12.jar; the most in front ";" is the current directory .
Method One thin
<% @ page import = "java.sql. *"%>
<% class.forname ("Oracle.jdbc.driver.OracleDriver"). NewInstance ();String Url = "JDBC: Oracle: Thin: @localhost: 1521: Shaird";
String User = "HS";
String password = "123321";
Connection conn = drivermanager.getConnection (URL, User, Password);
Statement stmt = conn.createStatement (ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); String sql = "select * from try"; ResultSet rs = stmt.executeQuery (sql); while (rs.next ()) {out.println (rs .getstring (1)); OUT.PRINTLN (rs.getstring (2));
Rs.close (); stmt.close (); conn.close ();%> body> html>
OK. Try it. This method is the simplest. Method 2 JDBCODBCDRIVER
Step 1: Enter Control Book -> Management Tools -> Data Source (ODBC)
-------------------------------------------------- -------------------------------- Step 2 TEST2.JSP
<% @ Page Info = "Database Handler"%> <% @ Page Import = "Java.io. *"%>
<% @ Page Import = "java.util. *"%>
<% @ page import = "java.sql. *"%> <% @ page import = "javax.servlet. *"%> <% @ page import = "javax.servlet.http. *"%>
<% class.forname ("sun.jdbc.odbc.jdbcodbcdriver"); string url = "jdbc: ODBC: HS";String User = "HS";
String password = "123321";
Connection conn = drivermanager.getConnection (URL, User, Password);
Statement Stmt = stmt = conn.createstatement (); string sql = "select * from try"; ResultSet RS = stmt.executeQuery (sql); while (rs.next ()) {%> <% = rs.getstring (1 )%> <% = rs.getstring (2)%> <%}%> <% rs.close (); stmt.close (); conn.close ();%> body> < / html>
The second method of ok is not trouble
Third
Connect pool (using the page configuration method with Tomcat5)
Step 1: Go to the main page of Tomcat5: http://127.0.0.1: 8181 (I am 8181 port, 8080 is occupied by Oracle) The Tomcat Administration password on the left of the page can be in the CONF folder under the Tomcat directory. Tomcat- Users.xml settings. Step 2: 1. Enter the tree map of the left to host-> context (/ TEST1) (this is the folder I used to test the page) -> Date Sources ------------- ---------------------------------------------- 2. After entering A new data source is established on the top of the right. -------------------------------------------------- --------- 3. Follow the following completion. The OK pool has been established.
Step three:
TEST3.JSP
<% @ page import = "java.sql. *"%> <% @ page import = "javax.sql. *"%> <% @ page import = "javax.naming. *"%> <% datasource ds = NULL;
InitialContext ctx = new InitialContext (); ds = (DataSource) ctx.lookup ( "java: comp / env / jdbc / oracle"); Connection conn = ds.getConnection (); Statement stmt = conn.createStatement (); String strSql = "Select * from try"; ResultSet RS = stmt.executeQuery (strsql); string aaa = "aa"; out.println (aaa); while (rs.next ()) {Out.println (rs.getstring (1 ))); Out.println (rs.getstring (2));}%> OK third type can also be used. hard. . .