JSP代码(添加,查询)

2008-02-23 09:28:01来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折

JSP技术:
----------------------------------------
public class ISOtoGb2312
{
public static String convert( String str )
{
try
{
byte<> bytesStr=str.getBytes( "ISO-8859-1" ) ;
return new String( bytesStr, "gb2312" ) ;
}
catch( Exception ex)
{
return str ;
}
}
}
-------------------------------------------------------------------
<%@ page contentType="text/html; charset=GB2312" %>
<html>
<head>
<title>
输入数据
</title>
</head>
<body bgcolor="#ffffff">
<h1>
请输入数据:
</h1>
<hr>
<form method="POST" action="insert.jsp">
<!--Webbot bot="SaveResults" U-File="fpweb:///_private/form_results.txt"
S-Format="TEXT/CSV" S-Label-Fields="TRUE" -->
<p> </p>

<p> </p>
<p><img border="0" src="img/cisco.gif" width="70" height="81">
<font size="5" color="#0000FF"><b>学 号:
</b></font><input type="text" name="id" size="25"> <img border="0" src="img/cisco.gif" width="70" height="81">
<font size="5" color="#0000FF"><b>性 别</b></font><font size="5" color="#0000FF"><b>:
</b></font><input type="text" name="sex" size="24"></p>
<p><img border="0" src="img/cisco.gif" width="70" height="81">
<font size="5" color="#000080"><b>姓 名:
</b></font><input type="text" name="name" size="25"> <img border="0" src="img/cisco.gif" width="70" height="81">
<font size="5" color="#0000FF"><b>年 龄: </b></font><input type="text" name="age" size="24"></p>

<p><img border="0" src="img/cisco.gif" width="70" height="81">
<font size="5" color="#000080"><b>地 址:
</b></font><input type="text" name="addr" size="84"> </p>

<p> </p>

<p>
<input type="submit" value="提交" name="B1" style="font-size: 14pt; font-weight: bold">
<input type="reset" value="全部重写" name="B2" style="font-size: 14pt; font-weight: bold">
</p>
</form>


</body>
</html>
---------------------------------------------------------------------
<%@ page contentType="text/html; charset=GB2312" %>
<%@ page import = "Java.sql.*"%>
<%@ page language = "java"%>
<%@ page import = "test.ISOtoGb2312"%>
<html>
<head>
<title>
添加数据
</title>
</head>
<body bgcolor="#ffffff">
<h1>
接收数据,添加到数据库.
</h1>
<%
Class.forName("sun.JDBC.odbc.JdbcOdbcDriver"); //载入驱动程序类别
Connection 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>

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:OSCache入门教程

下一篇:安裝Eclipse SVN Plugin