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

  • Home
  • SEARCH
  • 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 8811337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:20:21+00:00 2026-06-14T03:20:21+00:00

I am creating a simple registration frame that adds records onto a database. It

  • 0

I am creating a simple registration frame that adds records onto a database. It gives me an error message every time it runs the SQL query that adds records in the database, however it still adds them, but because of that my programs gets to a standstill, instead of opening another window.

here’s that part of the code:

regButton.addActionListener(new ActionListener() {

@Override public void actionPerformed( ActionEvent e ) {
   //Execute when button is pressed
   if(   uNameField.getText().equals("")
      || new String(newPassField.getPassword()).equals("")
      || new String(repeatPassField.getPassword()).equals("") ) {
      errorLabel.setForeground(Color.red);
      errorLabel.setText("Some fields are left blank");
   }
   else if( new String(newPassField.getPassword()).equals(
            new String(repeatPassField.getPassword()))){
      Statement stmt;
      ResultSet res;
      try
      {
         //SET USERNAME AND PASSWORD FROM FIELDS TO UPPER CASE
         String username = uNameField.getText().toUpperCase();
         String password = new String(newPassField.getPassword()).toUpperCase();
         //SQL INSERT QUERY
         String sql;
         sql = "INSERT INTO Employees VALUES ('" +username +"','" +password +"');";
         stmt = con.createStatement();
         res = stmt.executeQuery(sql);
         System.out.println("Added to database!");
         con.close();
      }
      catch(SQLException exe) {
         System.out.println("Error creating or running statement: " + e.toString());
         try {
            con.close();
         }
         catch(Exception eex){}
      }
   }
   else {
      errorLabel.setForeground(Color.red);
      errorLabel.setText("Password missmatch");
   }
}

Every time it registers a new employee (user) it displays this “Error creating or running statement: ….. ” although, I can find the newly added employees in the employee list.

What may be causing this problem?

  • 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-14T03:20:22+00:00Added an answer on June 14, 2026 at 3:20 am

    You need to use executeUpdate for SQL INSERTs

    int rowCount = stmt.executeUpdate(sql);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A lot of time when creating simple events in my program that other classes
Creating a simple RPG game, first time using XNA. Trying to get my character
I have an interface INavigationService and a simple container that allows registration with and
I think creating a simple user-registration on Orchard CMS should be easy? What I
getting error while creating simple maven project [WARNING] repository metadata for: 'org.apache.maven.plugins' could not
i am creating simple side menu, such that when the user hover on item
I'm creating simple application, some kind of portfolio. I've heard that it's better to
I'm creating a simple registration page: <?php $firstName = $_POST['firstName']; ?> <form action=registration.php method=post
I'm creating simple form validation that excludes any entries that have a letter in
I'm creating a registration system that needs to check the name/pass etc. with REGEX

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.