JSP新手求助
<%@ page language="java" contentType="text/html; charset=gb2312"
pageEncoding="gb2312"%>
<%@ page import="java.lang.*,java.io.*,java.sql.*,java.util.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@page import="com.sun.org.apache.bcel.internal.generic.IF_ICMPLE"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Insert title here</title>
</head>
<body>
<% String name=request.getParameter("username");
String nname=request.getParameter("Nickname");
String psw=request.getParameter("pwd").trim();
String ppsw=request.getParameter("pwdconfirm").trim();
String email=request.getParameter("email");
String que=request.getParameter("question");
String ans=request.getParameter("answer");
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String url="jdbc:sqlserver://localhost:1433;DatabaseName=bgh";
String user="sa";
String pwd="123456";
Connection cn=DriverManager.getConnection(url,user,pwd);
Statement stmt=cn.createStatement();
String sql1="select * from user_info where username ='"+name+"'";
Statement stmt1=cn.createStatement();
ResultSet rs=stmt1.executeQuery(sql1);
if(rs.next())
{
out.println("<br><br><center><B>请重新注册</B></center>");
out.println("<script>alert('对不起,用户名"+name+"已存在');location.replace('reg.jsp');</script>");
}else if(!psw.equals(ppsw)){
out.println("<script>alert('前后密码不一致,请确定密码');location.replace('reg.jsp')</script>");
}
else
{
int insertResult=0;
String sql2="INSERT INTO user_info(username,Nickname,pwd,email,question,answer) VALUES('"+name+"','"+nname+"','"+psw+"','"+email+"','"+que+"','"+ans+"',)";
insertResult=stmt.executeUpdate(sql2);
if(insertResult==0)
{
out.println("<script>alert('注册不成功');location.replace('reg.jsp')</script>"); }
else
{
out.println("<br><br><center><B>注册成功</B></center>");
out.println("<br><br><center>您的用户名是:"+name+"</center>");
out.println("<br><center>您的密码是: "+nname+"</center>");
out.println("<br><center>您的密码是: "+psw+"</center>");
out.println("<br><center>您的邮箱是: "+email+"</center>");
out.println("<br><center>您的电话是: "+que+"</center>");
out.println("<br><center>您的密码是: "+ans+"</center>");
out.println("<script>alert('谢谢注册,请登陆');location.replace('index.jsp')</script>");
}
}
%>
</body>
</html>
测试时显示红色字体的地方有错。应该怎么改呢?求助
[解决办法]
报的啥错?SQL拼接错了吧
[解决办法]
PreparedStatement ps = conn.prepareStatement(sql);