0

The code shows me the output as "com.mysql.jdbc.Driver" Is it because of the database or something? I am using JSP here and trying to verify details of users.

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <%@page import="java.sql.*"%>
        <%@page import="javax.sql.*" %>
        <%
        try{
        String username=request.getParameter("user");
        String password=request.getParameter("pwd");
        Class.forName("com.mysql.jdbc.Driver");
        Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3307/tyit1", "root", "sphinx1");
        Statement st=con.createStatement();
        ResultSet rs=st.executeQuery("select * from login where username='"+username+"' and password='"+password+"'");

        if(rs.next())
                       {
            String user=rs.getString("username");
            String pass=rs.getString("password");

        }
               else{
               out.print("Invalid Credentials!");
               }


        }
        catch(Exception e)
                               {
        out.println(e.getMessage());
        }

        %>
    </body>
</html>
Maionic
  • 25
  • 5
  • 1
    You should seriously consider moving your Java code out of the JSP page. – Tim Biegeleisen Sep 11 '16 at 08:50
  • What @TimBiegeleisen said. More info: [How to avoid Java code in JSP files?](http://stackoverflow.com/questions/3177733/how-to-avoid-java-code-in-jsp-files). – Pshemo Sep 11 '16 at 08:55
  • I'm sorry but this is a class I opted for and for now we have this chapter going on. So can you please point the error in this code for now? – Maionic Sep 11 '16 at 08:57
  • what's the problem? Any error? – SMA Sep 11 '16 at 09:00
  • Yeah, when I enter the username and password it shows, "com.mysql.jdbc.Driver" as output – Maionic Sep 11 '16 at 09:02
  • Replace `out.println(e.getMessage());` with `e.printStackTrace();` and then paste the entire error message you get on screen. – Balkrishna Rawool Sep 11 '16 at 09:54
  • Nothing gets printed on the screen :( – Maionic Sep 11 '16 at 09:58
  • Do you know what this program is supposed to do? I suspect that it is working well. – Balkrishna Rawool Sep 11 '16 at 10:06
  • Yes, it's supposed to check from the MySQL database the username and password. If correct just print Welcome or something but it prints com.mysql.jdbc.driver – Maionic Sep 11 '16 at 10:15
  • `e.printStackTrace()` will write the exception stacktrace to the log, not to the screen (i.e. the web page). Almost certainly the exception is a `ClassNotFoundException`, presumably because the MySQL JDBC driver JAR isn't on the build path/classpath/whatever-your-IDE-calls-it. – Luke Woodward Sep 11 '16 at 11:34
  • Add `out.println("Welcome");` immediately after `String pass=rs.getString("password");`. Post the output. – Balkrishna Rawool Sep 11 '16 at 15:57

0 Answers0