请问这个JAVA BEAN为什么用JSP调用显示错误呢?或者谁给我个从数据库查询用户名密码的登陆bean
package floatingpopulation;
import java.sql.*;
import java.util.*;
import java.io.*;
public class dengluBean{
String userid;
String password;
Connection conn=null;
Statement stmt=null;
ResultSet rs=null;
public void dengluBean(){
userid="";
password="";
}
public void setuserid(String user){
userid=user;}
public void setpassword(String pass){
password=pass;}
public String getuserid(){
return userid;}
public String getpassword(){
return password;}
public boolean getDataBaseUserid()throws Exception
{boolean getid=true;
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
}
catch(ClassNotFoundException e){e.printStackTrace();}
try{
conn=DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=floating population","sa","");
stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql="select * from student where UserName like "+"'"+userid+"'";
rs=stmt.executeQuery(sql);
if(rs.next()){
getid=true;}
else
{getid=false;}
conn.close();}
catch(SQLException e){System.out.println(e.getMessage());}
return getid;
}
public boolean validate(){
boolean ok=true;
if(userid.equals("")||userid.length()>10)
{ userid="";
ok=false;}
if(password.equals(" "))
{ password="";
ok=false;}
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
}
catch(ClassNotFoundException e){e.printStackTrace();}
try{
conn=DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=floating population","sa","");
stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql="select * from student where UserName like "+"'"+userid+"'";
rs=stmt.executeQuery(sql);
if(rs.next()){
ok=true;}
else
{ok=false;}
rs=null;
String sql1="select * from student where PassWord like "+"'"+password+"'";
rs=stmt.executeQuery(sql1);
if(rs.next())
{ok=true;}
else
{ok=false;}
conn.close();}
catch(SQLException e){System.out.println(e.getMessage());}
return ok;}
}
----------------解决方案--------------------------------------------------------
为什么要全部在JAVABEAN里实现呢
写一个SERVLET不什么都实现了吗
也可以用STRUTS写
一个JAVABEAN 和一个ACTION就实现了
感觉比这好多了
你这一个JAVABEAN又连接数据库又执行逻辑
太乱了
----------------解决方案--------------------------------------------------------