這是最簡單的壹個例子,數據庫要妳自己建,用的是ACCESS
<%@pagecontentType="text/html;charset=gb2312"language="java"import="java.sql.*"errorPage=""%>
<html>
<head>
<metancon=DriverManager.getConnection("jdbc:odbc:jspdata");//建立數據庫鏈接,jspdata為ODBC數據源名稱
//建立Statement對象
Statementstmt=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
ResultSetrs=stmt.executeQuery("select*fromlyb");//建立ResultSet(結果集)對象,並執行SQL語句
%>
</p>
<palign="center">NUMB1數據表中記錄如下</p>
<tablewidth="640"border="1"align="center"bordercolor="7188e0">
<trbgcolor="d1d1ff">
<thwidth="49">編號</th>
<thwidth="90">姓名</th>
<thwidth="126">E-mail</th>
<thwidth="221">網站</th>
<thwidth="80">QQ</th>
</tr>
<%
while(rs.next())
{
%>
<trbgcolor="f8f8f8">
<th><%=rs.getString(1)%></th>
<th><%=rs.getString(2)%></th>
<th><%=rs.getString(3)%></th>
<thbgcolor="f6f6f8"><%=rs.getString(4)%></th>
<th><%=rs.getString(5)%></th>
</tr>
<%
}
rs.close();
stmt.close();
con.close();
%>
</table>
<palign="center"><br>
如果您能看到表格中的數據,說明連接數據庫成功!</p>
</body>
</html>