• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

jsp: Connectivity issue using jsp and mysql in netbeans

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 :)
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Step 1: move all that code out of a JSP and into a Java class where it belongs! JSP is for view generation, not control.

If this is part of an authentication system, first you should find previous discussions where Tim will advise you not to roll your own. But it you insist, this sort of check should be done in filters.
 
Deepika Choudhari
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey thanks for the suggestion,but previously I have used jsp code for bussiness logic and it run very well but there I have used Oracle for Database,this time I m using mysql but its showing error. I am developing a live website for the first time,so I am not understanding how to connect to Database.
Thanks for the reply!
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let me know when you have moved the code into a Java class and we can look at the it in its new home.
 
yeah, but ... what would PIE do? Especially concerning this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic