Can anyone see what the problem is?

Hi
I get this message whilst trying to debug this jsp: SQLException:java.sql.SQLException: Syntax error or access violation, message from server:
"You have an error in your SQL syntax near email = 'null'AND password = 'null'' at line 1"
Here is the JSP code:
<%
String email = request.getParameter("username");
String password = request.getParameter("ppassword");
String user_type = null;
mylogin.connect();
ResultSet loginResult = mylogin.viewLogon(email, password);
loginResult.next();
if (loginResult != null)
%>
Incorrect Username or Password Entered. Please try again!
Please clickHere to Go Back!
<%
if (loginResult.first())
user_type = request.getParameter("user");
}else if (user_type.equals("patient"))
%>
<jsp:forward page="homepage.jsp" />
<%
}else if (user_type.equals("staff"))
%>
<jsp:forward page="outofhoursstaff.jsp" />
<% }else if (user_type.equals("admin"))
%>
<jsp:forward page="siteadminmain.jsp" />
<%
%>
<% mylogin.disconnect(); %>
Here is the JavaBean code:
public ResultSet viewLogon(String email, String password) throws SQLException, Exception
     ResultSet loginResult = null;
     try
          String queryString = ("SELECT user_type, email, password" +
                                   "FROM user" +
                                   "WHERE email = '"+email+"'" +
                                   "AND password = '"+password+"'");
          Statement statement = con.createStatement();
          Statement stmt = con.createStatement();
          loginResult = statement.executeQuery(queryString);
     catch (SQLException sqle)
          System.out.println("SQLException:" + sqle);
     catch (Exception e)
          System.out.println("Exception:" + e);
     return loginResult;
Any suggestions will be gratefully appreciated

I think you need some spaces in your code - It would have produced
SELECT user_type, email, passwordFROM userWHERE email ='null'AND password ='null'
You need to include spaces where you are concatenating the strings.
String queryString = ("SELECT user_type, email, password" +
" FROM user" +
" WHERE email = '"+email+"'" +
" AND password = '"+password+"'");
As an aside, I would also suggest that you use a prepared statement, and substitute in the parameters
ie WHERE email = ? and password = ?
This will
- Protect you from stupid people who put quotes in their passwords
- prevent SQL injection attacks.
Cheers,
evnafets

Similar Messages

Maybe you are looking for

  • Can I buy a television 32 inch for a mac mini and have a good image quality?

    Hello I want to buy a tv 32 inch for work with videos, the image on tv will be good ?

  • Creating PDFs from a PDF in Snow Leopard

    All, With Snow Leopard, I'm unable to create a PDF from a PDF using Acrobat 8 or 9 because it doesn't work and theres no fix, yet. What I do.... someone mails me a PDF, I make comments, fill in info, etc, and need to create another PDF from that one

  • Sub contracting scrap

    Hi, for which T-codes am using for mvt 544 and 545 to get the scrap from sub-contracting vendor rgds

  • Export Current Setting Problem

    We currently use DVCProHD footage/timeline, etc. 1280x1080 DVCPro Pixel aspect... all that. We export to quicktime using Current Settings so we can use it on different editors with no additional rendering needed. Here's the problem: The export change

  • OS X Yosemite upgrade for MacBook Pro

    I know some people have found updating to OS X Yosemite an issue so I thought would check with the experts. I have 17-inch, Early 2011. Processor  2.2 GHz Intel Core i7. Memory 4 GB 1333 MHz DDR3. Software  Mac OS X Lion 10.7.5 (11G63). Hard drive 75