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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:27:24+00:00 2026-06-04T16:27:24+00:00

For school I’m working on a program that connects to a MySQL database and

  • 0

For school I’m working on a program that connects to a MySQL database and perform queries such as an ATM machine might.

So far I’ve made a simple program where I’ve been putting my connection code in the submit button, but now I need to support many different buttons for balance query, withdrawal, etc.

For my initial screen where the user enters their login and PIN I have the following code, but I’m kind of lost as to how I can do these queries under other buttons with the variables I have in this button:

private void bSubmitActionPerformed(java.awt.event.ActionEvent evt) {                                        
    String login = jLogin.getText();
    String pin = jPin.getText();


    try {
        Connection con = DriverManager.getConnection("jdbc:mysql://localhost/bankaccount", "root", "password");

        Statement st = (Statement) con.createStatement();
        PreparedStatement ps;
        String sqlCommand;
        ResultSet rs;

        sqlCommand = "SELECT * FROM accounts WHERE loginID= '" + login + "' AND pin='" + pin + "'";

        rs = st.executeQuery(sqlCommand);

        if (rs.next()) {

            do {

                card2.setVisible(true);
                card1.setVisible(false);



            } while (rs.next());
        } else {
            jWarning.setText("please try again");
        }





    } catch (Exception e) {
    }
}
  • 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-04T16:27:27+00:00Added an answer on June 4, 2026 at 4:27 pm
        public ResultSet execute(String sqlCommand ){
    
        ResultSet rs = null;
    
        try {
            Connection con = DriverManager.getConnection("jdbc:mysql://localhost/bankaccount", "root", "password");
    
            Statement st = (Statement) con.createStatement();
            PreparedStatement ps;
    
    
            rs = st.executeQuery(sqlCommand);
    
    
        } catch (Exception e) {
        }
    
        return rs;
    
    }
    
    
    public void submitButton1(){
         String login = jLogin.getText();
        String pin = jPin.getText();
    
    ResultSet rs = execute("SELECT * FROM accounts WHERE loginID= '" + login + "' AND pin='" + pin + "'");
    
       /// do whatever with your rs
    
    }
    
    public void submitButton2(){
         String login = jLogin.getText();
        String pin = jPin.getText();
    
    ResultSet rs = execute("more sql");
    
       /// do whatever with your rs
    
    }
    

    appending the update method:

    public int update(String sqlCommand ){
    
           int affected_rows = 0;
            try {
                Connection con = DriverManager.getConnection("jdbc:mysql://localhost/bankaccount", "root", "password");
    
                Statement st = (Statement) con.createStatement();                
    
                affected_rows = st.executeUpdate(sqlCommand);
    
    
            } catch (Exception e) {
            }
    
            return affected_rows;
    
        }
    

    The update method also can be used to insert and delete. An update statament could be something like this:

    update accounts  
    set columnA = "a value",  
    columnB = "other value"  
    where loginID = 4;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In school we've been taught that compilers compile a computer program to machine language.
As a school assignment, I am supposed to create a program in C# that
I have a old school c program that now and then need to tell
For my school project, I am working on a database management application. It is
For school I need to make a program in JavaScript that says if circles
Our school's ERP has a nasty database structure to it and since it is
In school I am part of a team of four working to create a
For a school project I need to create a program and it'd be nice
When in school it was often a requirement to flowchart the little programs that
I am a high school student and am thinking of making a robot that

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.