Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8947457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:45:59+00:00 2026-06-15T12:45:59+00:00

I am having this problem which should not be a problem i have written

  • 0

I am having this problem which should not be a problem

i have written this code

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Scanner;

/**
 * @author ZEESHAN
 */
public class TestApps 
{
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) 
    {
        // TODO code application logic here
        Connection con;
        // Statement stmt;
        ResultSet rs;
        String str,str2,str3;
        try 
        {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            con=DriverManager.getConnection("jdbc:odbc:TestApp");

            Statement stmt =  con.createStatement();
            System.out.println("Connected");

            rs=stmt.executeQuery("SELECT Emp_Name,Emp_LastName FROM Table_1 WHERE Emp_Name = 'zeeshan' ");

            while(rs.next()) 
            {
                str = rs.getString("Emp_Name");
                str2 = rs.getString("Emp_LastName");
                String name,pass;    

                Scanner input = new Scanner(System.in);
                name = input.nextLine();
                pass = input.nextLine();

                if(name.equals(str) && pass.equals(str2) )
                {
                    System.out.println("CORRECT");
                }
                else
                {
                    System.out.println("INCORRECT");
                    System.out.println(""+name);
                    System.out.println(""+pass);
                    System.out.println(""+str);
                    System.out.println(""+str2);
                }
            }

            //  String name,pass;    

            /*   
            if(name.equals(str) && pass.equals(str2) )
            {
                System.out.println("Correct");
            }
            else
            {
                System.out.println("Incorrect");
            }
            */
        }
        catch (Exception ex)
        {
            System.out.println("Not connected");
            ex.printStackTrace();
        }
    }
}

Everything works fine, i.e. database and all. I giving the same answer as the database string, but I get this result which is not fine and also the result says all strings are the same answer, but why I still don’t get in the true condition I am getting the false condition my answer in console.

RESULT:
 INCORRECT
 zeeshan
 ismail
 zeeshan   
 ismail  
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T12:46:00+00:00Added an answer on June 15, 2026 at 12:46 pm

    There are trailing spaces in the value of str and str2. You have to trim to values before comparing the string.

    str = str.trim();
    str2 = str2.trim();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having this problem in JS - which is not my native language at
This is similar to an earlier problem I was having which you guys solved
I've having this problem with some JavaScript code. I've simplified it in the error
So i'm having this problem. I have two tables (Oracle), one is called Destination
Hey dudes.i am having this problem while symlinking. I have successfully deployed a ruby
I am having this problem with my ASP.Net application and I have no idea
I have a program, written in Java, which originally used its directory in Program
Possible Duplicate: window.onload vs document.ready jquery i am having this problem: i have an
I have this static function which basicly makes a connection to a webpage, send
I'm having this problem where I keep getting this error in my console: *

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.