Yesterday, I did a good job in this three things. I believe that everyone will understand: 3 The path of the new chain database.
<% @ Page ContentType = "text / html; charset = GB2312"%>
<% @ Page Import = "java.sql. *"%>
<%
Class.Forname ("Org.gjt.mm.mysql.driver"). NewInstance ();
Connection conn = drivermanager.getConnection ("JDBC: MySQL: // LocalHost / Test", "root", "123456");
StatementStmt = Conn.createStatement (ResultSet.Type_Scroll_Sensitive, ResultSet.concur_updatable);
String SQL = "SELECT * from STU";
ResultSet RS = Stmt.executeQuery (SQL);
While (rs.next ())
{%>
<% = rs.getstring ("xh")%>
<% = rs.getstring ("xm")%>
<%}%>
body>
html>
-------------------------------------------------- -------------------------------------------------- ----------------------------------------
Server.xml
UserdatabaseEnderalm to Authenticate Uses ->
Type = "org.apache.catalina.userdatabase" Description = "User Database That Can Be Updated and Saved" Factory = "org.apache.catalina.users.MemoryUserDatabaseFactory" Pathname = "conf / tomcat-users.xml" /> TYPE = "javax.sql.datasource" Driverclassname = "com.mysql.jdbc.driver" Username = "root" PASSWORD = "123456" Maxidle = "2" maxwait = "5000" URL = "JDBC: mysql: // localhost / test" Maxactive = "4" /> Globalnamingresources> Contex.xml Context> Web.xml resource-ref> <% @ Page Import = "java.sql. *"%> <% @ Page Import = "javax.sql. *"%> <% @ Page Import = "javax.naming. *"%> <% @ Page session = "false"%>
hEAD>
<%
Out.print ("START");
Try {
CONTEXT INITCTX = New InitialContext ();
Context CTX = (Context) INitctX.lookup ("Java: Comp / ENV");
Object obj = (object) CTX.lookup ("JDBC for MySQL");
Javax.sql.datasource DS = (javax.sql.datasource) OBJ;
Connection conn = ds.getConnection ();
Out.print ("MySQL Connection Pool Runs Perfectly!");
Statement Stmt = Conn.createStatement (ResultSet.Type_Scroll_Sensitive,
ResultSet.concur_updatable;
String SQL = "SELECT * from STU";
ResultSet RS = Stmt.executeQuery (SQL);
While (rs.next ())
{%>
<% = rs.getstring ("xh")%> <% = rs.getstring ("xm")%>
<%}%>
<%
CONN.CLOSE ();
}
Catch (Exception EX) {
Out.print (ex.getMessage ());
EX.PrintStackTrace ();
}
%>
body>
html>
-------------------------------------------------- -------------------------------------------------- ---------------------------------
Struts-config.xml
data-source>
data-sources>
Three needed packages:
Commons-dbcp-1.2.1.jar
http://apache.linuxforum.net/dist/jakarta/commons/dbcp/binaries/
Struts-legacy.jar
http://apache.linuxforum.net/dist/jakarta/struts/struts-legacy/
Commons-pool-1.2.jar
http://apache.linuxforum.net/dist/jakarta/commons/pool/binaries/
H: / java / tomcat 5.5 / common / lib / mysql-connector-java-3.0.16-ga-bin.jar;
-------------------------------------------------- -------------------------------------------------- -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
J2EE architecture began today
But on Saturday, I want to test the final exam, ---- I am bother, this day is not able to live, China's programmer is not talent, but slaves, is right.