Hey friends,
Anybody can help me to sort out my problem in getting connected to mysql database using
jsp in netbeans. I have a login page and i want to login using uid and pwd, when i enter it displays invalid username and password although i have inserted uid and pwd in table called 'login' in mysql!!! Here I have the following code---
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.lang.*" %>
<%@page import="java.sql.*" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>login Page</title>
</head>
<body>
<%!
Connection con;
Statement st;
ResultSet rs;
String uid,pwd;
%>
<%
try
{
uid=request.getParameter("uid"); // uid is text field name of html page
pwd=request.getParameter("textfield"); // textfield is text field name of html page
uid=uid.trim();
pwd=pwd.trim();
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/contact","root",""); // 'contact' database name
if(con==null)
{
out.println("Connection not opened");
}
else
{
out.println("Connection opened");
out.println("DB is connected");
st=con.createStatement();
String q="select * from login where username='"+uid+"' and password='"+pwd+"'";
rs=st.executeQuery(q);
while(rs.next())
{
%>
<jsp:forward page="Developers login page.html"></jsp:forward>
<%
}
out.println("Sorry...Invalid username and password.Please try again later");
}
}
catch(Exception e)
{
out.println(e.toString());
}
%>
</body>
</html>
instead of going to "
Developers login page.html" its displaying error message as "
Sorry...Invalid username and password.Please try again later" !!!
please help me in fixing out this issue! It will be very helpfull...
regards :)