Type mismatch: cannot convert from int to ResultSet
<%@pagecontentType="text/html;charset=GB2312"%><%@pageimport="java.sql.*"%><%//姓名Stri...
<%@ page contentType="text/html;charset=GB2312"%>
<%@ page import="java.sql.*"%>
<% //姓名
String txt_username =request.getParameter("txt_username");
if(txt_username==null)
{
txt_username="";
}
byte name[]=txt_username.getBytes("ISO-8859-1");
txt_username=new String(name);
//密码
String txt_pwd =request.getParameter("txt_pwd");
if(txt_pwd==null)
{
txt_pwd="";
}
byte pwd[]=txt_pwd.getBytes("ISO-8859-1");
txt_pwd=new String(pwd);
//新密码
String txt_chkpwd =request.getParameter("txt_chkpwd");
if(txt_chkpwd==null)
{
txt_chkpwd="";
}
byte chkpwd[]=txt_chkpwd.getBytes("ISO-8859-1");
txt_pwd=new String(chkpwd);
//密码问题
String select =request.getParameter("select");
if(select==null)
{
select="";
}
byte select1[]=select.getBytes("ISO-8859-1");
select=new String(select1);
// 答案
String txt_pwdanswer=request.getParameter("txt_pwdanswer");
if(txt_pwdanswer==null)
{
txt_pwdanswer="";
}
byte pwdanswer[]=txt_pwdanswer.getBytes("ISO-8859-1");
txt_pwdanswer=new String(pwdanswer);
//出生日期
String sel_byear=request.getParameter("sel_byear");
String sel_bmonth=request.getParameter("sel_bmonth");
String sel_bday=request.getParameter("sel_bday");
String bytime=sel_byear+sel_bmonth+sel_bday;
//性别
String chk_sex =request.getParameter("chk_sex");
if(chk_sex==null)
{
chk_sex="";
}
byte sex[]=chk_sex.getBytes("ISO-8859-1");
chk_sex=new String(sex);
//邮箱
String txt_email =request.getParameter("txt_email");
if(txt_email==null)
{
txt_email="";
}
byte email[]=txt_email.getBytes("ISO-8859-1");
txt_email=new String(email);
//验证码
/* String txt_vcode=(String)request.getParameter("txt_vcode");
if(txt_vcode==null)
{
txt_vcode="";
}
*/
//连接数据库
Connection conn=null;
Statement stmt=null;
ResultSet rs=null;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}catch(ClassNotFoundException e)
{
out.print("类找不到!");
}
try
{
conn=DriverManager.getConnection("jdbc:odbc:sun","sa","");
stmt=conn.createStatement();
String condition="INSERT INTO STUDENTS VALUES('"+ txt_username+"','"+txt_pwd+"','"+txt_chkpwd+"','"+bytime+"','"+txt_email+"')";
rs=stmt.executeUpdate(condition);
conn.close();
}
catch(SQLException sql)
{
out.print("SQL异常!");
}
%>
</BODY>
</HTML> 展开
<%@ page import="java.sql.*"%>
<% //姓名
String txt_username =request.getParameter("txt_username");
if(txt_username==null)
{
txt_username="";
}
byte name[]=txt_username.getBytes("ISO-8859-1");
txt_username=new String(name);
//密码
String txt_pwd =request.getParameter("txt_pwd");
if(txt_pwd==null)
{
txt_pwd="";
}
byte pwd[]=txt_pwd.getBytes("ISO-8859-1");
txt_pwd=new String(pwd);
//新密码
String txt_chkpwd =request.getParameter("txt_chkpwd");
if(txt_chkpwd==null)
{
txt_chkpwd="";
}
byte chkpwd[]=txt_chkpwd.getBytes("ISO-8859-1");
txt_pwd=new String(chkpwd);
//密码问题
String select =request.getParameter("select");
if(select==null)
{
select="";
}
byte select1[]=select.getBytes("ISO-8859-1");
select=new String(select1);
// 答案
String txt_pwdanswer=request.getParameter("txt_pwdanswer");
if(txt_pwdanswer==null)
{
txt_pwdanswer="";
}
byte pwdanswer[]=txt_pwdanswer.getBytes("ISO-8859-1");
txt_pwdanswer=new String(pwdanswer);
//出生日期
String sel_byear=request.getParameter("sel_byear");
String sel_bmonth=request.getParameter("sel_bmonth");
String sel_bday=request.getParameter("sel_bday");
String bytime=sel_byear+sel_bmonth+sel_bday;
//性别
String chk_sex =request.getParameter("chk_sex");
if(chk_sex==null)
{
chk_sex="";
}
byte sex[]=chk_sex.getBytes("ISO-8859-1");
chk_sex=new String(sex);
//邮箱
String txt_email =request.getParameter("txt_email");
if(txt_email==null)
{
txt_email="";
}
byte email[]=txt_email.getBytes("ISO-8859-1");
txt_email=new String(email);
//验证码
/* String txt_vcode=(String)request.getParameter("txt_vcode");
if(txt_vcode==null)
{
txt_vcode="";
}
*/
//连接数据库
Connection conn=null;
Statement stmt=null;
ResultSet rs=null;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}catch(ClassNotFoundException e)
{
out.print("类找不到!");
}
try
{
conn=DriverManager.getConnection("jdbc:odbc:sun","sa","");
stmt=conn.createStatement();
String condition="INSERT INTO STUDENTS VALUES('"+ txt_username+"','"+txt_pwd+"','"+txt_chkpwd+"','"+bytime+"','"+txt_email+"')";
rs=stmt.executeUpdate(condition);
conn.close();
}
catch(SQLException sql)
{
out.print("SQL异常!");
}
%>
</BODY>
</HTML> 展开
2个回答
展开全部
rs=stmt.executeUpdate(condition);
这句话有问题。
rs是记录集ResultSet对象,而stmt.executeUpdate()方法则返回所更新的记录条数,为int型,所以出现类型转换错误。建议改成:
int updateNumber=stmt.executeUpdate(condition);
这句话有问题。
rs是记录集ResultSet对象,而stmt.executeUpdate()方法则返回所更新的记录条数,为int型,所以出现类型转换错误。建议改成:
int updateNumber=stmt.executeUpdate(condition);
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询