vendredi 19 janvier 2018

Java "if statement" doesn't work with database [duplicate]

This question already has an answer here:

I have this script that is supposed to check if the values from an HTML "form" element match with the values in a database.

<%
    //Storing the variables from a form element
    String nameJava = request.getParameter("name");
    String passJava = request.getParameter("pass");

    //Establish connection with the database
    Class.forName("org.sqlite.JDBC");
    Connection conn = DriverManager.getConnection("jdbc:sqlite:d:\\Databases\\DataBase1.db");
    Statement stat = conn.createStatement();

    ResultSet rs = stat.executeQuery("select * from users;");

    //Check the database for the correct value
    while (rs.next()) {
        if(rs.getString("name") == nameJava && rs.getString("password") == passJava) {
             //Does not go inside,it was supposed to go.
             foundJava = true;
        } 
    }

    rs.close();
    conn.close();
%>

The problem is, the if statement doesn not return "true". Any help is appreciated.

Aucun commentaire:

Enregistrer un commentaire