Friday, 5 October 2012

Login and Registration using JSP , MS Access Database

// siddhu vydyabhushana // 3 comments
As per too many requests am going to explain detail database connection using jsp and ms access .Java server pages are dynamic so we are using it for db connections.Coming to scripting jsp is most flexible and reliable than others,but present php leading good role in web designing..................

Last Posts:

1)Oracle Database Connection 
2)MS Access Database Connection 

HTML CODE PIC FOR LOGIN :



JSP CODE FOR LOGIN.JSP:   

here we used request.getParameter   to get values from one session to another. I used try , catch method when an error occur it will goes to ctach field.





Code designed by #Siddhu Vydyabhushana Subscribe Me


<%@ page import="java.sql.*"%>
<%
try
{
String user2=request.getParameter("username");
String pass2=request.getParameter("password");

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:epoll","","");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select pass from user where user='"+user2+"' and pass='"+pass2+"'");
if(rs.next())
{
String pass3=rs.getString("pass");
String flag1=rs.getString("flag");
if(flag1.equals(str)==true)
{

if (pass3.equals(pass2)==true)
{
session.putValue("user1",user2);
response.sendRedirect("user.jsp");
}
}
}
else
{%>
<script>
alert("invalid login");
response.sendRedirect("epoll.html");

</script>

<%}
con.close();
}
catch(Exception e)
{
out.println("done exception"+e);

}

HTML PIC FOR SIGNUP:-



signup.jsp code:   here we used request.getParameter   to get values from one session to another. I used try , catch method when an error occur it will goes to ctach field.



Code designed by #Siddhu Vydyabhushana Subscribe Me

<%@ page import="java.sql.*"%>
<%
try
{
String user1=request.getParameter("username");
String email1=request.getParameter("email");
String pass1=request.getParameter("password");
int flag=0;
String str=Integer.toString(flag);
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:epoll","","");
PreparedStatement pst= con.prepareStatement("insert into user values(?,?,?,?)");
pst.setString(1,user1);
pst.setString(2,email1);
pst.setString(3,pass1);
pst.setString(4,str);

pst.executeUpdate();

con.close();
}
catch(Exception e)
{
out.println("done exception"+e);

}
%>

3 comments: