title: How to retrieve sha1 hash values in mysql database for my java code
body: <p>I created function to authenticate user in java. I use <code>SHA1</code> to encrypted data and I stored it in MySQL. Then I created parametric query to pass data from MySQL database.But I had an error in that query line. After I changed <code>SHA1</code> values in database and I remove the <code>SHA1</code> word in my query. Really it's work without any errors. But I want to get and check <code>SHA1</code> encrypt data from database. How to pass database <code>SHA1</code> encrypted data into my query. Please someone help me to solve my problem.  </p>
  
  <pre><code>public boolean authenticate(String username, String password){
      Connection newConnection = null;
      ResultSet newRst = null;
      boolean flag = false; //return value which determines whether logged in or not
      String SqlString = "SELECT * FROM user"
              + " WHERE username=? AND password=SHA1(?)"; //Error line when use SHA1()
  
      String Username = username;
      String Password = password;
  
      String CheckUsername;
      String CheckPassword;
  
      List&lt;String&gt; ParametersDefined =
              Arrays.asList(Username, Password);
      List&lt;String&gt; ParametersNames =  Arrays.asList("username", "password");
      List&lt;String&gt; ParameterDataType =
              Arrays.asList("String", "String");
  
      DatabaseHandling newData = new DatabaseHandling();
      try {
  
          newConnection = newData.DataConnection();// creating the connection
          newRst = newData.DataReadArg(newConnection, SqlString,
                  ParametersDefined, ParametersNames, ParameterDataType);
          //check whether one row or more 
  
          int RowCount = 0; // to find the row count
          while (newRst.next()) {
              //checking whether we are getting right row
              System.out.println("this is " + newRst.getString(2));
  
              RowCount++;
          }
          //if the Row count is one then it check    
          if (RowCount == 1) {
              newRst.first();
              CheckUsername = newRst.getString("username");
              CheckPassword = newRst.getString("password");
  
              if ((username.equals(CheckUsername))
                      &amp;&amp; password.equals(CheckPassword)) {
                  userRoleId = newRst.getInt("userRoleId");
                  System.out.println("role = " + userRoleId);
                  flag = true;
              }
          }
  
      } catch (Exception e) {
  
          System.out.println("Error" + e.getMessage());
          flag = false;
  
      }
  
      return flag;
  }
  </code></pre>
  
  <p><em>Working line...</em></p>
  
  <blockquote>
    <p><code>String SqlString = "SELECT * FROM user"
                    + " WHERE username=? AND password=?"; //Without SHA1 String. It's working without any errors.</code></p>
  </blockquote>