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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:03:02+00:00 2026-06-12T07:03:02+00:00

This is a small part of the application where user can register any number

  • 0

This is a small part of the application where user can register any number of employees and employee id is generated by using a while loop….As i close the application & start filling the data again in second round…the value of employee id empid resets to zero. Well, as long as the application is running, i get the desired o/p i.e. a unique id is allotted to every employee. I dont want empid‘s value to start from 0 whenever i start the application. Need alternatives and/or any modification. Code is provided here

int empcount=0;
    public void actionPerformed(ActionEvent ae) {
            //---------------------If user wants to add data
            if(ae.getActionCommand()=="ADD EMPLOYEE") {
                System.out.println("ADDING");
        try{
            empcount=empcount+1;//----------------will assign employees with unique emp id
            //--------------------returns the text in name field to variables 
            String s_name=name.getText();
            int s_code=empcount;
            String s_dept=dept.getText();
            String s_ph=ph.getText();
            String s_bg=bg.getText();
            String s_add=add.getText();
            String s_date=date.getText();
            PreparedStatement st=null;
            Connection con = null;
            Class.forName("org.hsqldb.jdbcDriver");
            con = DriverManager.getConnection("jdbc:hsqldb:hsql://localhost/", "SA", "");
            st=con.prepareStatement("Insert into EmpReg (emp_name,emp_code,emp_ph,emp_bg,emp_add,emp_date,b_id) values(?,?,?,?,?,?,?)");
            //---------------------parameters and respective values, passed to the SQL statement
            st.setString(1,s_name);
            st.setInt(2,s_code);
            st.setString(3,s_ph);
            st.setString(4,s_bg);
            st.setString(5,s_add);
            st.setString(6,s_date);
            st.setString(7,s_dept);
            st.execute();
            JOptionPane.showMessageDialog(null,"Data is inserted into the database");
            JOptionPane.showMessageDialog(code, "employee code"+ empcount+"");
            con.close();
        }
            catch(Exception Ee){
            System.out.println(Ee);
            }
                }       
            }
        });
  • 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-12T07:03:03+00:00Added an answer on June 12, 2026 at 7:03 am

    The standard SQL way of doing this, is having an “autoincrement” primary key (emp_code), for hsqldb see IDENTITY.
    In the SQL INSERT statement leave out the primary key. Now the database generates a unique new key.
    After the execution, you can retrieve the generated primary key from the statement with getGeneratedKeys.

    This ensures that two parallel processes will not mess up the primary keys.

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

Sidebar

Related Questions

Work on this small test application to learn threading/locking. I have the following code,
I am working on a small web application right now and part of the
My ASP.NET MVC application is a small part of a bigger ColdFusion app that
I need to parse files generated by a third-party application. Using ANTLR, I have
I'm currently developing a QT application with a coworker. My particular part of this
I encountered a code design problem while working on a small application. In terms
I am building a small Android application which will add a cube on user's
As part of my application, I'm putting together a set of small Dom nodes
I've built a small application which has User Management, a frontend console to enter
Consider this small program: #include <stdio.h> #include <stdlib.h> // Change 60000 to 70000 and

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.