當前位置:編程學習大全網 - 源碼下載 - jsp中網站的首頁源代碼

jsp中網站的首頁源代碼

這是最簡單的壹個例子,數據庫要妳自己建,用的是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>

  • 上一篇:Spring 源碼分析 —— 服務優雅關閉
  • 下一篇:找個CS1.6服務器插件--進去的玩家顯IP地址
  • copyright 2024編程學習大全網