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 9086483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:30:02+00:00 2026-06-16T21:30:02+00:00

Hello I am trying to create a login form in java netbeans IDE. My

  • 0

Hello I am trying to create a login form in java netbeans IDE. My aim is to create multiple user ID’s and their respective passwords. I have given textfields to userID and passwordField for passwords to get the values but the problem is i want to get the text from the password field and i am unable to get it its showing some error i think there is some problem with syntax my research is as follows can there be any solution? Need your help

private void lb_loginMouseClicked(java.awt.event.MouseEvent evt) {                                      
       DBUtil util = new DBUtil();
       String value1=tb_uid.getText();
       String value2=tb_pwd.getPassword();
       String user1="";
       String pass1="";
       try {

            Connection con = util.getConnection();
            PreparedStatement stmt = con.prepareStatement("SELECT * FROM login where username='"+value1+"' && password='"+value2+"'");
            ResultSet res = stmt.executeQuery();
            res = stmt.executeQuery();
            while (res.next()) {
                user1 = res.getString("username");
                pass1 = res.getString("password");
            }
            if (value1.equals(user1) && value2.equals(pass1)) {
            JOptionPane.showMessageDialog(this,"correct");
            }
            else{
            JOptionPane.showMessageDialog(this,"Incorrect login or password","Error",JOptionPane.ERROR_MESSAGE);
            }
            JOptionPane.showMessageDialog(null, "COMMITED SUCCESSFULLY!");
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, ex.getMessage());

        }

    }  
  • 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-16T21:30:03+00:00Added an answer on June 16, 2026 at 9:30 pm

    value2 is char array so doing String concatenation would result in the String representation of the array rather then the String content itself ending up in the SQL. You could replace

    PreparedStatement stmt = con.prepareStatement("SELECT * FROM login where username='"+value1+"' && password='"+value2+"'");
    

    with

    PreparedStatement stmt = con.prepareStatement("SELECT * FROM login where username='"+value1+"' AND password='" + new String(value2) + "'");
    

    Similarly

    if (value1.equals(user1) && value2.equals(pass1)) {
    

    would need to be

    if (value1.equals(user1) && pass1.equals(new String(value2)) {
    

    Better use the PreparedStatement placeholders however, to protect against SQL injection attack:

    PreparedStatement stmt = con.prepareStatement("SELECT * FROM login where username=? AND password=?);
    stmt.setString(1, value1);
    stmt.setString(2, new String(value2));
    

    Note: This is not a secure way do to a password lookup, a hashed comparison would be relatively safer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create an Hello World JSF application. I have a bean with
What I try to do Hello Guys, I'm trying to create a Login-Screen which
Hello there i'm trying to create a form with Zend_Form that will enable my
**Hello, I'm trying to create an archiver in java. This means that I am
Hello I am trying to create a simple neo4j DB. I have a for
Hello I'm trying to create a on-line photalbum. So the idea is to have
Hello I'm trying to create grouping in the pdf file and I have to
Hello and thank you in advance, I am trying to create a django form
Hello i am trying to create a login and session script with php to
Hello I am trying to create a custom expandable listview, but the documentation on

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.