& lt% @ page content type = " text/html;charset = GB 2312 " language = " Java " import = " Java . SQL . * " error page = " " " & gt;
& lthtml & gt
& lthead & gt
& ltmetan con = driver manager . getconnection(" JDBC:odbc:JSP data ");//建立數據庫鏈接,以jspdata作為ODBC數據源名稱。
//創建壹個語句對象
statements TMT = con . create statement(ResultSet。TYPE_SCROLL_INSENSITIVE
結果集。CONCUR _ READ _ ONLY);
results etrs = stmt . execute query(" select * from lyb ");//創建壹個ResultSet對象並執行SQL語句。
% & gt
& lt/p & gt;
& ltpalign="center " >NUMB1數據表記錄如下
& lttablewidth = " 640 " border = " 1 " align = " center " border color = " 7188 E0 " >
& lttrbgcolor="d1d1ff " >
& ltthwidth="49 " >號碼
& ltthwidth="90 " >名字
& ltthwidth="126 " >電子郵件& lt/th & gt;
& ltthwidth="221 " >網站(全球資訊網的主機站)
& ltthwidth="80 " >QQ & lt/th & gt;
& lt/tr & gt;
& lt%
while(rs.next())
{
% & gt
& lttrbgcolor="f8f8f8 " >
& ltth & gt& lt% = RS . getstring(1)% & gt;& lt/th & gt;
& ltth & gt& lt% = RS . getstring(2)% & gt;& lt/th & gt;
& ltth & gt& lt% = RS . getstring(3)% & gt;& lt/th & gt;
& ltthbgcolor="f6f6f8 " >的問題。& lt% = RS . getstring(4)% & gt;& lt/th & gt;
& ltth & gt& lt% = RS . getstring(5)% & gt;& lt/th & gt;
& lt/tr & gt;
& lt%
}
RS . close();
stmt . close();
con . close();
% & gt
& lt/table & gt;
& ltpalign="center " >& ltbr & gt
如果您可以看到表中的數據,那麽與數據庫的連接是成功的!& lt/p & gt;
& lt/body & gt;
& lt/html & gt;