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?
You can try this answer..:)