示例数据库 jspsqlsample.mdb

表: info

列

名称 类型 长度

编号 长整型 4

name 文本 50

gender 文本 50

·在 jsp_test 目录下建立 mypage20.jsp：

<%@ page pageEncoding="gb2312" %>

<%@ page contentType="text/html;charset=gb2312"%>

<%@ page pageEncoding="gb2312" %>

<%@ page contentType="text/html;charset=gb2312"%>

<%@ page import="java.sql.*" %>

<%request.setCharacterEncoding("gb2312");%>

<%

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

String url = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=" + "D://work//jsp_test//jspsqlsample.mdb";

Connection conn=DriverManager.getConnection(url);

Statement stmt = conn.createStatement();

ResultSet rs = stmt.executeQuery("select * from info");

%>

<html>

<head>

<title> 学习 JSP </title>

<style type="text/css">

<!--

.STYLE1 {color: #FFFFFF}

-->

</style>

</head>

<body>

<table width="387" border="1" cellpadding="1" cellspacing="0" bgcolor="#000066">

<tr bgcolor="#9999FF">

<th width="184"><span class="STYLE1">姓名</span></th>

<th width="187"><span class="STYLE1">性别</span></th>

</tr>

<%

while( rs.next())

{

out.println("<tr bgcolor=\"#FFFFFF\"><td>"+rs.getString(2)+"</td><td>"+rs.getString(3)+"</td></tr>");

}

%>

</table>

</body>

</html>

<%

stmt.close();

conn.close();

%>