Mysql> Select * from users;
-- ------- ---------- -------------- | ID | Name | Password | CreateTime | ---- ------- ---------- -------------- | 1 | Bitan | Bbbbbbbb | 20050202035511 || 2 | Helen | HHHHHHHHHH | 20050202035526 || 3 | Susan | sssssssss | 20050202035541 | ---- ------- ------------ ---------------- 3 ROWS IN SET (0.00 SEC)
K: / Tomcat/conf/server.xml
......
Context>
Host>
Engine>
Service>
Server>
K: /TEST26/Web-inf/web.xml
XML Version = "1.0" encoding = "UTF-8"?>
<% @ Page ContentType = "Text / HTML; Charset = GBK"%> <% @ page import = "java.sql. *"%> <% try {javax.naming.initialcontext ic = new javax.naming.initialcontext ); Javax.sql.datasource ds = (javax.sql.datasource) Ic.lookup ("java: comp / env / jdbc / mydata); // JNDI name Sets Connection conn = in Web.xml and Server.xml DS.GetConnection (); statement stmt = conn.createstatement (); resultset = stmt.executeQuery ("select * from users"); while (rs.next ()) {Out.println (rs.getstring (2) "," rs.getstring (3) "
");}}}} catch (javax.naming.namingexception ne) {out.println (ne.getMessage ());} catch (java.sql.sqlexception se) ) {Out.println (se.getMessage ());}%>
result:
Bitan, Bbbbbbbbhelen, Hhhhhhhhhhhhhhhhhhhhh, Sssssssss