import java
import java
public class DAOUtil {
public DAOUtil() {
}
public static Connection getConn() {
Connection conn = null;
String db_url =
String db_user =
String db_password=
String db_driver =
try {
Class
conn = DriverManager
} catch (Exception ex) {
ex
}
return conn;
}
/**
* dbclose
* 關閉Connection
* @param conn Connection
* @param stmt Statement
*/
public static void dbclose(Connection conn
try {
if (stmt != null)
stmt
} catch (Exception e) {
e
}
try {
if (conn != null)
conn
} catch (Exception e) {
e
}
}
}
import java
import java
import java
import java
public class PersonDAO {
static PersonDAO pdao;
public static PersonDAO getInstance() {
if (pdao == null) {
synchronized (PersonDAO
pdao = new PersonDAO();
}
}
return pdao;
}
public PersonDAO() {
super(); }
public static void main(String[] args) {
System
}
private static List getPersonInfo() {
String name =
String password =
Connection conn = null;
List list = new java
Statement stmt = null;
String sql =
try {
conn = DAOUtil
stmt = conn
ResultSet rs = stmt
while (rs
name = (String)rs
password = (String)rs
list
}
} catch (Exception ex) {
ex
} finally {
DAOUtil
}
return list;
}
}
<%@page contentType=
<%@page import=
<%@page import=
<html>
<body bgcolor=
test
<table width=
<tr>
<td width=
<td width=
<td width=
</tr>
<%
//todo connect mysql server (localhost root/admin) and test(db) person(table)
List list =PersonDAO
System
for(int i=
String namePass = (String)list
java
String name = st
String pass = st
System
%>
<tr>
<td><div align=
<td> <div align=
<td><div align=
</tr>
<%
}
%>
</table>
</body>
</html>
修改WEB
<?xml version=
<!DOCTYPE web
<web
<display
<taglib><taglib
<filter>
<filter
<filter
</filter>
<filter
<filter
<url
</filter
</web
啟動tomcat
修改WEB
<?xml version=
<!DOCTYPE web
<web
<display
<filter>
<filter
<filter
<init
<param
<param
</init
<init
<param
<param
</init
</filter>
<filter
<filter
</filter
<url
</filter
</web
其中
From:http://tw.wingwit.com/Article/program/Java/JSP/201311/19148.html