ection con = DriverManager.getConnection("jdbc:odbc:zjyds1"); //建立数据库链接
Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
String strSQL;
strSQL = "INSERT INTO tab02(id, name, sex, " +
"age, addr) Values (" +
ISOtoGb2312.convert( request.getParameter("id")) + "," +
ISOtoGb2312.convert( request.getParameter("name")) + "," +
ISOtoGb2312.convert( request.getParameter("sex")) + "," +
ISOtoGb2312.convert( request.getParameter("age")) + "," +
ISOtoGb2312.convert( request.getParameter("addr")) + ")";
stmt.executeUpdate(strSQL);
ResultSet rs; //建立ResultSet(结果集)对象
rs = stmt.executeQuery("SELECT * FROM tab02"); //执行SQL语句
%>
<CENTER>
<TABLE bgcolor=pink>
<TR bgcolor=silver>
<TD><B>编号</B></TD><TD><B>姓 名 </B></TD><TD><B>性 别</B></TD><TD><B> 年 龄</B></TD><TD><B>地 址</B></TD>
</TR>
<%
//利用while循环将数据表中的记录列出
while (rs.next())
{
%>
<TR bgcolor=white>
<TD><B><%= rs.getString("id") %></B></TD>
<TD><B><%= rs.getString("name") %></B></TD>
<TD><B><%= rs.getString("sex") %></B></TD>
<TD><B><%= rs.getString("age") %></B></TD>
<TD><B><%= rs.getString("addr") %></B></TD>
</TR>
<%
}
rs.close(); //关闭ResultSet对象
stmt.close(); //关闭Statement对象
con.close(); //关闭Connection对象
%>
</TABLE>
</CENTER>
<h3><a href="jsp1.jsp">返回</a></h3>
</body>
</html>
-----------------------------------------------------------------------------------
留言内容:
jsp1:
<%@ page contentType="text/html; charset=GB2312" %>
<%@ page import="com.borland.internetbeans.*,com.borland.dx.dataset.*,com.borland.dx.sql.dataset.*" %>
<%@ taglib uri="/internetbeans.tld" prefix="ix" %>
<%@ taglib uri="http://java.sun.com/jstl/sql" prefix="sql" %>
<html>
<head>
<title>
jsp1
</title>
</head>
<jsp:useBean id="jsp1BeanId" scope="session" class="test.Jsp1Bean" />
<jsp:setProperty name="jsp1BeanId" property="*" />
<body bgcolor="#ff00ff">
<h1>
JBuilder Generated JSP
<br>
<hr>
这是第一次使用JSP技术 !!!----2004/3/1--南昌大学软件学院----
</h1>
<h3><a href="tmp/page_1.htm">另一页</a></h3>
<br>
<h3><a href="jsp2.jsp">下一页</a></h3>
<br>
<h3><a href="DBBean.jsp">数据库</a></h3>
<form method="post">
<br>Enter new value : <input name="sample"><br>
<br>
<input type="submit" name="Submit" value="Submit">
<input type="reset" value="Reset">
<br>
Value of Bean property