紧急求助,JSP向SQLServer2000插入数据出错。
代码如下,运行后抛出异常执行catch里的语句而没有执行try中的语句,不知道是什么原因,请大家赐教。
<%@ page contentType= "text/html; charset=gb2312 " %>
<%@ page import= "XiaoYuJob.util.*,java.sql.*,java.io.*,java.util.*,javax.servlet.http.HttpServletRequest "%>
<%//request.setCharacterEncoding( "GB2312 ");%>
<jsp:useBean id= "jobSeeker " class= "XiaoYuJob.job.JobSeeker " scope= "request " />
<!--构造jobSeeker类的对象 jobSeeker-->
<jsp:setProperty name= "jobSeeker " property= "* "/>
<!--设置对象jobSeeker的属性-->
<%
DealString str=new DealString();
ShowErrorBox show=new ShowErrorBox();
out.print( "sssss "+jobSeeker.getSusername());
if(jobSeeker.getSusername()==null||jobSeeker.getStruename()==null||
jobSeeker.getConfirm()==null)
{
out.print(show.errorBox( "请添写完整信息! ", "错误信息 "));
return;
}
else
{
if(jobSeeker.getSusername().compareTo( "z ")> =0||jobSeeker.getSusername().compareTo( "0 ") <=0)
{
out.print(show.errorBox( "注册用户名不允许为特殊字符和汉字! ", "错误信息 "));
return;
}
if(!jobSeeker.getPassword().equals(jobSeeker.getConfirm()))
{
out.print(show.errorBox( "密码不相同,请重新输入! ", "错误信息 "));
return;
}
try
{
Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver ").newInstance();
String url= "jdbc:microsoft:sqlserver://localhost:1305;DatabaseName=XiaoYuJob "; // XiaoYuJob是数据库名称
String user= "sa ";
String password= " ";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql= "insert into t_user (username,password,type)values( ' "+
jobSeeker.getSusername()+ " ', ' "+jobSeeker.getPassword()+ " ', '1 ') ";
stmt.executeUpdate(sql);