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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:24:58+00:00 2026-05-27T10:24:58+00:00

I finally got the password, the queries, the button and the connection, but how

  • 0

I finally got the password, the queries, the button and the connection, but how come it Seems I can’t seem to log in? what’s wrong with my Action Handler? please check my code

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.JButton;
import javax.swing.JPanel;
import java.sql.*;

public class Login extends JFrame {

    private JLabel label1, label2;
    private JButton submit;
    private JTextField textfield1;
    private JPasswordField passfield;
    private JPanel panel;

    public Login() {

        setSize(300, 100);
        setVisible(true);

        label1 = new JLabel("User ID:");
        textfield1 = new JTextField(15);
        label2 = new JLabel("Password:");
        passfield = new JPasswordField(15);
        submit = new JButton("Submit");
        panel = new JPanel(new GridLayout(3, 1));

        panel.add(label1);
        panel.add(textfield1);
        panel.add(label2);
        panel.add(passfield);
        panel.add(submit);
        add(panel, BorderLayout.CENTER);

        ButtonHandler handler = new ButtonHandler();
        submit.addActionListener(handler);
    }// end login constructor

    private class ButtonHandler implements ActionListener {

        public void actionPerformed(ActionEvent arg0) {

            String user = textfield1.getText();
            char[] passChars = passfield.getPassword();
            Connection conn = Jdbc.dbConn();
            PreparedStatement ps = null;
            ResultSet rs = null;
            String pass = new String(passChars);

            if (passChars != null) {
                String sql = "SELECT employee_ID,employee_password FROM user where" +
                          "employee_ID='user' and employee_password=+'pass'";

                try {
                    ps = conn.prepareStatement(sql);
                    ps.setString(1, user);
                    ps.setString(2, pass);
                    rs = ps.executeQuery();
                    if (rs.next()) {
                        user = rs.getString("employee_id");
                        pass = rs.getString("employee_password");
                        JOptionPane.showMessageDialog(null,"Welcome "+user);
                    } else {
                        JOptionPane.showMessageDialog(null, "Wrong Input");
                    }
                } catch (Exception e) {

                } finally {
                    try {

                        rs.close();
                        ps.close();
                        conn.close();
                    } catch (Exception ee) {

                    }
                }

            }// end actionPerformed

        }// End ButtonHandler

    }// End of class
}
  • 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-05-27T10:24:59+00:00Added an answer on May 27, 2026 at 10:24 am

    you have two choices for PreparedStatement, both are correct

    1) change String sql = .... definition

    String sql = "SELECT employee_ID, employee_password FROM 
        user WHERE employee_ID = ? AND employee_password = ?";
    

    2) put variables to the SQL statement directly

    String sql = "SELECT employee_ID, employee_password FROM user WHERE 
         employee_ID = '" + user + "' AND employee_password = '" + pass + "'";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I finally got around to trying out django-devserver . It's installed and working but
I finally got Socket.IO to work properly, but I have encountered a strange problem.
I finally got all of my queries written (thanks to all who have helped
I finally got my code to reference the ruby-alsa library , but I'm stuck
I finally got my localhost to display the site locally. Everything seems to be
I finally got some understanding of how Ninject handles DI, but have faced the
Well I added and finally got Sharekit to work with facebook using FBConnect, but
I finally got some parts working here: http://jsfiddle.net/trXBr/5/ but when I put the code
I finally got my app to be able to send text messages (SMS), but
I finally got my group to switch from SourceSafe to Subversion. Unfortunately, my manager

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.