Posted By:
sheela_oba
Posted On:
Wednesday, October 31, 2007 12:16 PM
Below is my java bean class in which i defined a module called verifyregis(),where i established a JDBC connection to verify whether given username and password already exists in the database, if they already exists the boolean value for registered variable is true else it is false i just called this module in a jsp page and checked whether if registered value is true i just want to go to one page and if false i want to go to another page...i just could not get the code correct in the jsp page, i could not access the module in java bean class in jsp page... package myproject; import java.sql.*; public class myprojbean { private String id;
More>>
Below is my java bean class in which i defined a module called verifyregis(),where i established a JDBC connection to verify whether given username and password already exists in the database, if they already exists the boolean value for registered variable is true else it is false
i just called this module in a jsp page and checked whether if registered value is true i just want to go to one page and if false i want to go to another page...i just could not get the code correct in the jsp page, i could not access the module in java bean class in jsp page...
-
package myproject;
-
import java.sql.*;
-
public class myprojbean
-
{
-
private String id;
-
private String passwd;
-
private String retypepwd;
-
private String fname;
-
private String lname;
-
private String gender;
-
private boolean registered;
-
public myprojbean()
-
{}
-
public void setid(String id)
-
{
-
this.id=id;
-
}
-
public String getid()
-
{
-
return id;
-
}
-
public void setpasswd(String passwd)
-
{
-
this.passwd=passwd;
-
}
-
public String getpasswd()
-
{
-
return passwd;
-
}
-
public void setretypepwd(String retypepwd)
-
{
-
this.retypepwd=retypepwd;
-
}
-
public String getretypepwd()
-
{
-
return retypepwd;
-
}
-
public void setfname(String fname)
-
{
-
this.fname=fname;
-
}
-
public String getfname()
-
{
-
return fname;
-
}
-
public void setlname(String lname)
-
{
-
this.lname=lname;
-
}
-
public String getlname()
-
{
-
return lname;
-
}
-
public void setgender(String gender)
-
{
-
this.gender=gender;
-
}
-
public String getgender()
-
{
-
return gender;
-
}
- public void verifyregis()throws
-
SQLException,ClassNotFoundException
-
{
-
Connection con=null;
-
PreparedStatement pstmt;
-
ResultSet rs;
-
try
-
{
-
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
-
con=DriverManager.getConnection("jdbc:odbc:oradsn","scott","tiger");
-
pstmt=con.prepareStatement("select id,passwd from login_info where id='"+id+"' and passwd='"+passwd+"'");
-
rs=pstmt.executeQuery();
-
while(rs.next())
-
{
-
if(id.equalsIgnoreCase(rs.getString(1))&&passwd.equalsIgnoreCase(rs.getString(2)))
-
registered=true;
-
}
-
else
-
{
-
registered=false;
-
}
-
rs.close();
-
}
-
finally
-
{
-
con.close();
-
}
-
}
-
public void insertdata()throws SQLException,ClassNotFoundException
-
{
-
Connection con=null;
-
PreparedStatement pstmt=null;
-
ResultSet rs;
-
String str="insert into login_info values(?,?,?,?,?,?)";
-
try
-
{
-
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
-
con=DriverManager.getConnection("jdbc:odbc:oradsn","scott","tiger");
-
pstmt=con.prepareStatement(str);
pstmt.setString(1,id);
-
pstmt.setString(2,passwd);
-
pstmt.setString(3,retypepwd);
-
pstmt.setString(4,fname);
-
pstmt.setString(5,lname);
-
pstmt.setString(6,gender);
-
pstmt.executeUpdate();
-
}
-
finally
-
{
-
con.close();
}
}
}
jsp page:
-
<%@ page errorPage="/error.jsp"%>
-
class="myproject.myprojbean"/>
-
-
<% boolean b=myprojbean.verifyregis();%>
-
<% if(b==true)
-
{%>
-
-
<%}else{%>
-
-
<%}%>