1) Download mm.mysql-2.0.14-bin.jar package, place in the CommON / lib folder under the Tomcat directory
2) Join before host> in the CONF / Server.xml under the Tomcat directory (Note: All uppercase places should be replaced with your own things)
<-! For mysql database connection pool ->
Value> JDBC: mysql: // localhost: 3306 / database_name? Autoreconnect = true value> parameter>
! - Maximum Time to Wait for A DB Connection To Become Available In MS. AN Exception Is Thrown if this timeout is excsseded. Set to -1 to wait indefinitely .-->
Database_name: TestDB
Application_name: MySQLTEST
New Table UserInfo in TestDB Database
ID | Username1 aaa2 bbb
4) Web.xml
5) Index.jsp
<% @ Page ContentType = "Text / HTML; Charset = GB2312" Language = "Java" Import = "java.sql. *, javax.naming. *"%>
<% Context infectx = new initialcontext (); context ctx = (context) INITCTX.LOOKUP ("java: comp / env"); object obj = (object) CTX.lookup ("JDBC / TestDB"); Javax.sql. DataSource ds = (javax.sql.DataSource) obj; Connection conn = ds.getConnection (); Statement stmt = conn.createStatement (); String strSql = "select * from userinfo"; ResultSet rs = stmt.executeQuery (strSql); %>
<% while (rs.next ()) {%><% = rs.getstring ("Username")%> p> <%}%>
It can be seen that the output is:
Aaabbb