Results 1 to 4 of 4
  1. #1
    naveen516 is offline Member
    Join Date
    Dec 2011
    Posts
    6
    Rep Power
    0

    Default java.SQLException

    import java.io.IOException;
    import java.io.PrintWriter;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.sql.ResultSet;
    import java.sql.Statement;
    import org.omg.IOP.ServiceContext;
    public class EmpServlet extends HttpServlet
    {
    public void doPost(HttpServletRequest req, HttpServletResponse res)throws ServletException,IOException
    {
    String name=req.getParameter("username");
    String pwd=req.getParameter("password");
    name=name.toLowerCase();
    String s1=null;
    String s2=null;
    String s3=null;
    String s4=null;
    String s5=null;
    res.setContentType("text/html");
    PrintWriter out=res.getWriter();
    out.println(name);
    try
    {

    Class.forName("sun.jdbc.odbc.JdbcOdbcDrive");
    Connection con= DriverManager.getConnection("jdbc:odbc:employee"," system","sanjay16");
    Statement stmt=con.createStatement();
    ResultSet rs1=stmt.executeQuery("select empid from employee where empname="+name);

    while(rs1.next())
    {
    s5=rs1.getString(1);
    }
    ResultSet rs=stmt.executeQuery("select * from employee where empid="+s5);
    while(rs.next())
    {
    s1=rs.getString(1);
    s2=rs.getString(2);
    s3=rs.getString(3);
    s4=rs.getString(4);
    }
    HttpSession session=req.getSession();
    session.setAttribute("employeeid",s5);
    if(s2.equals(name)&&pwd.equals(s3))
    {
    out.println("Welcome "+name+"\n");
    out.println("<html><body background=bcg.jpg>"+"<h1>Your Profile</h1>");
    out.println("Name is :"+s2+"<br></br>");
    out.println("Employee id is :"+s1+"<br></br>");
    out.println("Password is :"+s3+"<br></br>");
    out.println("Sallery is :"+s4+"<br></br>");
    out.println("<center>");
    out.println("<form method=post action=LeaveHistoryServlet>");
    out.println("<input type=submit value=LeaveHistory >"+"<br></br>");
    out.println("</form");
    out.println("</center>");
    out.println("</html>"+"</body>");
    }
    else
    {
    out.println("<html><head></head><body background=bcg.jpg><h2>Sorry,Username or password is wrong</h2></body></html>");
    }

    out.close();
    rs.close();
    stmt.close();
    con.close();
    }
    catch(Exception e)
    {
    e.printStackTrace();
    }
    }
    }





    This is my code, from the html code i am entering username and password as naveen,1111 respectively.
    I am using type1 driver and Apachi tomcat server.
    It is giving java.sql.SQLException that ORA-0094 'NAVEEN' invalid identifier.
    And even after printing 'name' value it is printing small case 'naveen' only.


    Can anyone please help me?

  2. #2
    DeNiS_M is offline Member
    Join Date
    Sep 2011
    Location
    Athens Greece
    Posts
    29
    Rep Power
    0

    Default Re: java.SQLException

    I think the problem is in this line:
    Java Code:
    ResultSet rs1=stmt.executeQuery("select empid from employee where empname="+name);
    try it like this:
    Java Code:
    ResultSet rs1=stmt.executeQuery("select empid from employee where empname=' "+name+" ' ");

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,225
    Rep Power
    20

    Default Re: java.SQLException

    Better yet, use a PreparedStatement, and setString(1,name).

  4. #4
    d3n1s is offline Member
    Join Date
    Apr 2011
    Posts
    69
    Rep Power
    0

    Default Re: java.SQLException

    Both are correct, you need a quote to surround a string value in SQL. Prepared statements allow you to not worry about that stuff though :)

Similar Threads

  1. java.sql.SQLException: Closed Connection
    By sunjavaboy in forum JDBC
    Replies: 4
    Last Post: 03-21-2012, 02:38 PM
  2. java.sql.SQLException:
    By nandhinianand in forum New To Java
    Replies: 2
    Last Post: 09-28-2011, 08:15 AM
  3. java.sql.sqlException
    By harsimran05 in forum JDBC
    Replies: 1
    Last Post: 09-06-2011, 01:14 PM
  4. Replies: 0
    Last Post: 01-21-2011, 01:43 PM
  5. Replies: 2
    Last Post: 06-07-2010, 09:45 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •