suzhou111
suzhou111
2009-09-01 10:49

jsp与数据库的问题

  • it技术
  • 互联网问答
  • IT行业问题
  • 编程语言问答
  • 计算机技术

我写了一个小程序

是用html页面提交给jsp页面处理登陆 我把链接数据库都封装到了一个类里面,对数据库的操作也是一样
但是 他给我报ResultSet没当前行 是什么? 下面是我的代码
这是JSP页面的
<%
javabean obj = new javabean();
String name = request.getParameter("txtUserName");
String pass = request.getParameter("txtUserPassword");
String yanzhengma = request.getParameter("txtName");
obj.setTxtUserNmae(name);
obj.setTxyUserPass(pass);
ResultSet rs = obj.yanzheg();
int namelength = name.length();
int passlength = pass.length();
int yanzhengmalength = yanzhengma.length();
String varcode = (String)session.getAttribute("varcode");
String str1 = rs.getString(1);
System.out.println("------------------------------");
String str2 = rs.getString(2);
if( namelength != 0 && passlength != 0 && yanzhengmalength != 0)
{
System.out.println("ccccccccccccccc");
while(rs.next())
{
if(varcode.equals(yanzhengma))
{
if(str1.equals(name) && str2.equals(pass))
{
out.print("window.alert(&#39;登陆成功&#39;)");
out.print("window.location.herf=&#39;login.jsp&#39;");
}
}
else
{
out.print("window.alert(&#39;验证码输入错误,请重新输入&#39;)");
out.print("window.location.herf=&#39;login.jsp&#39;");
}

}

out.print("window.alert(&#39;无此用户或用户密码错误&#39;)");
out.print("window.location.herf=&#39;login.jsp&#39;");
}
else
{
out.print("window.alert(&#39;输入不完整,请检查输入&#39;)");
out.print("window.location.herf=&#39;login.jsp&#39;");
}
%>
这是JAVABEAN的
package org.baijie8.JDBC;

import java.sql.ResultSet;
import java.sql.SQLException;

public class javabean {
private String TxtUserNmae;
private String TxyUserPass;
public String getTxtUserNmae() {
return TxtUserNmae;
}
public void setTxtUserNmae(String txtUserNmae) {
TxtUserNmae = txtUserNmae;
}
public String getTxyUserPass() {
return TxyUserPass;
}
public void setTxyUserPass(String txyUserPass) {
TxyUserPass = txyUserPass;
}

public ResultSet yanzheg()
{
try {
User u = new User();
ResultSet rs = u.resultset(this);
return rs;
}
catch (SQLException e){
e.printStackTrace();
}
return null;
}
}
package org.baijie8.JDBC;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class User {
private Connection conn= null;
public ResultSet resultset(javabean user) throws SQLException
{
try
{
JdbcUtil ju =new JdbcUtil();
conn = ju.getsqlConnection();
String sql = "select * from controller_info where controller_name=? and controller_pass=?";
PreparedStatement ps = conn.prepareStatement(sql);
ps.setString(1,user.getTxtUserNmae());
ps.setString(2, user.getTxyUserPass());
return ps.executeQuery();
}
catch (SQLException e)
{
e.printStackTrace();
}
return null;
}
}

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

4条回答