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 src="https://www.jb51.net/img/cisco.gif"> <font size="5" color="#0000FF"><b>学 号: </b></font><input type="text" size="25"> <img src="https://www.jb51.net/img/cisco.gif"> <font size="5" color="#0000FF"><b>性 别</b></font><font size="5" color="#0000FF"><b>: </b></font><input type="text" size="24"></p> <p><img src="https://www.jb51.net/img/cisco.gif"> <font size="5" color="#000080"><b>姓 名: </b></font><input type="text" size="25"> <img src="https://www.jb51.net/img/cisco.gif"> <font size="5" color="#0000FF"><b>年 龄: </b></font><input type="text" size="24"></p> <p><img src="https://www.jb51.net/img/cisco.gif"> <font size="5" color="#000080"><b>地 址: </b></font><input type="text" size="84"> </p> <p> </p> <p> <input type="submit" value="提交"> <input type="reset" value="全部重写"> </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> <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="https://www.jb51.net/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 scope="session" /> <jsp:setProperty property="*" /> <body bgcolor="#ff00ff"> <h1> JBuilder Generated JSP <br> <hr> 这是第一次使用JSP技术 !!!----2004/3/1--南昌大学软件学院---- </h1> <h3><a href="https://www.jb51.net/tmp/page_1.htm">另一页</a></h3> <br> <h3><a href="https://www.jb51.net/jsp2.jsp">下一页</a></h3> <br> <h3><a href="https://www.jb51.net/DBBean.jsp">数据库</a></h3> <form method="post"> <br>Enter new value : <input><br> <br> <input type="submit" value="Submit"> <input type="reset" value="Reset"> <br> Value of Bean property is :<jsp:getProperty property="sample" /> </form> <h3><a href="https://www.jb51.net/jsp4.jsp">登录</a></h3> </body> </html>

Jsp1Bean.java

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wzfwyx.html