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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:10:31+00:00 2026-06-10T19:10:31+00:00

I have a MySql table in which I have a column named payslip_no which

  • 0

I have a MySql table in which I have a column named payslip_no which is set as an AUTO_INCREMENT. I want to set this auto incremented value to the value of a text box at the time of page load.

Another way is I am trying to increment this number programatically without setting the column as ‘AUTO_INCREMENT’. Following is the code:

public void get_payslip_no()
{

int n1 =0;
try
{
rs2=st2.executeQuery("select max(payslip_no) from tbl_add_payroll");
if(rs2.next())
{
n1=rs2.getInt("payslip_no");
n1=n1+1;
String n2 = Integer.toString(n1);
txt_payslip_no.setText(n2);
System.out.println(n2);                   
}
}//try
catch(SQLException e2)
{
 JOptionPane.showMessageDialog(this,"Payroll-Serial no Storing Error!!!","Serial No Error",JOptionPane.INFORMATION_MESSAGE);    
}//catch
}

This code is throwing A NullPointerException because the current database is null. How might I resolve this?

  • 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-10T19:10:33+00:00Added an answer on June 10, 2026 at 7:10 pm

    You can try this answer..:)

    int no=101;
        int no1;
    try
            {
               dbStatement = con.createStatement();
               dbResult= dbStatement.executeQuery("select payslip_no from tbl_add_payroll ORDER BY  payslip_no  DESC LIMIT 1");
    
              if(dbResult.next()==false)
              {
                   jTextField3.setText(String.valueOf(no));
    
              }
             else
              {         
                dbResult= dbStatement.executeQuery("select payslip_no from tbl_add_payroll ORDER BY payslip_no DESC LIMIT 1");      
                        while(dbResult.next())
    
                               {
                               deptno=dbResult.getInt("payslip_no");
    
                                 }
    
    
                                 no1=deptno+1;
                                 jTextField3.setText(String.valueOf(no1));
              }
    
    
         }catch(Exception E)
         {
    
         }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a server table which has a column named 'SN' in mysql, when
I have a MySQL table with a datetime column named 'created' which contains the
i have a large mysql database table in which one column contains values ranging
I have a mysql table which columns are post_id and post_msg. Now I want
I have a table which looks like this: mysql> SHOW COLUMNS FROM Users; +------------+--------------+------+-----+---------+----------------+
I have this mysql table called comments which looks like this: commentID parentID type
I have a mysql table field set as time type which stores data in
I have a Mysql table which contains a column of JSON data and a
I have a MySQL database and a table which has a names column as
i have a column named name which is present in all tables in mysql

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.