【JSP开源代码栏目提醒】:网学会员在JSP开源代码频道为大家收集整理了acceptInsertUserTable.jsp提供大家参考,希望对大家有所帮助!
<%@ page contentType="text/html;charset=GB2312" %>
<%@ page import="java.sql.*" %>
<%!
public String codeToString(String str)
{//处理中文字符串的函数
String s=str;
try
{
byte tempB[]=s.getBytes("ISO-8859-1");
s=new String(tempB);
return s;
}
catch(Exception e)
{
return s;
}
}
%>
<%//接收客户端提交的数据
String username=codeToString(request.getParameter("username"));
if(username==null)//无内容则设为空串
username="";
String password=codeToString(request.getParameter("password"));
if(password==null)//无内容则设为空串
password="";
String usertruename=codeToString(request.getParameter("usertruename"));
if(usertruename==null)//无内容则设为空串
usertruename="";
String age=codeToString(request.getParameter("age"));
int ageint;
try
{
ageint=Integer.parseInt(age.trim());
}
catch(Exception e)
{
ageint=0; //没有输入年龄或输入的年龄不是数字则值为0
}
String sex=codeToString(request.getParameter("sex"));
if(sex==null)//无内容则设为空串
sex="";
String address=codeToString(request.getParameter("address"));
if(address==null)//无内容则设为空串
address="";
String telephone=codeToString(request.getParameter("telephone"));
if(telephone==null)//无内容则设为空串
telephone="";
%>
<%//构造追加记录SQL语句
String sqlString=null;//SQL语句
sqlString="insert into userTable(user_name,user_password,user_true_name,user_age,user_sex,user_address,user_telephone)"+
" values('"+username+"','"+password+"','"+usertruename+"',"+ageint+",'"+sex+"','"+address+"','"+telephone+"')";
%>
<%//执行SQL语句
try
{ Connection con;
Statement sql;
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
con=DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=testDatabse","sa","");
sql=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
sql.executeUpdate(sqlString);
con.close();
}
catch(SQLException e1)
{
out.print("SQL异常!");
}
%>
<head>
<title>用户注册程序</title>
</head>
<body>
<center>
<table border="1" width="700">
<tr>
<td width="100%" colspan="2" align="center">用户注册程序</td>
</tr>
<tr>
<td width="100%" colspan="2">追加用户成功!</td>
</tr>
</table>
</center>
</body>
</html>
上一篇:
AccepteUploadFile.jsp
下一篇:
下鼻甲不同术式对鼻黏膜纤毛功能的影响