📄 charu (3).jsp
字号:
<%@ page contentType="text/html; charset=GB2312" %>
<%@ page import="java.sql.*" %>
<html>
<head>
<title></title>
<META http-equiv="Content-Type" content="text/html; charset=GB2312">
</head>
<body>
<%
String name=request.getParameter("name");
if(name==null)
{
name="";
}
byte b[]=name.getBytes("ISO-8859-1");
name=new String(b);
String sex=request.getParameter("sex");
if(sex==null)
{
sex="";
}
byte s[]=sex.getBytes("ISO-8859-1");
sex=new String(s);
String age=request.getParameter("age");
String dept=request.getParameter("dept");
if(dept==null)
{
dept="";
}
byte d[]=dept.getBytes("ISO-8859-1");
dept=new String(d);
Connection con;
Statement sql;
ResultSet rs;
Statement stmt;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e){}
try
{
con=DriverManager.getConnection("jdbc:odbc:conn");
sql=con.createStatement();//创建SQL语句对象.
stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
stmt.executeUpdate("INSERT INTO stuInfo VALUES ('"+name+"','"+sex+"','"+age+"','"+dept+"')");
rs=sql.executeQuery("SELECT* FROM stuInfo");
%>
<center>
<h2>学生信息表</h2>
<br />
<br />
<h4>输出插入后的学生信息:</h4>
<table border="1" bgcolor="#cccccc"><!--设置用以表格显示.-->
<tr>
<th width="50">学号</th>
<th width="50">姓名</th>
<th width="50">性别</th>
<th width="50">年龄</th>
<th width="50">系别</th>
</tr>
<%
while(rs.next())//顺序取出结果集中的数据.
{%>
<tr>
<td><%=rs.getString(1)%></td> <!---取出表中第一个字段-->
<td><%=rs.getString(2)%></td>
<td><%=rs.getString(3)%></td>
<td><%=rs.getInt(4)%></td>
<td><%=rs.getString(5)%></td>
</tr>
<%}%>
</table>
</center>
<%
con.close();
}
catch(SQLException e1)
{
System.out.println(e1);
}
%>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -