Click here to Skip to main content
15,889,403 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I designed one form in java where textfield is there.so I want to display serial numbers in this textfield...means current textfield value should be 1..then I'll fill up these form and submitted...when I'll come back textfield value should be 2...after submitting this form textfield value become 3 and so on...So how to make auto increment serial number and display in JTextfield..

What I have tried:

Here I used java eclipse and sqlite database.
I tried following code


textField = new JTextField();
try
{
String query="Select max(`Enquiry No`) as max from enquiry ";
PreparedStatement pst=conn.prepareStatement(query);
ResultSet rs=pst.executeQuery();

while(rs.next())
{
int num = rs.getInt("max");
int inc=num+1;
textField.setText(valueOf(inc));

}

}

catch(Exception a)
{
a.printStackTrace();
}
Posted
Updated 22-Feb-17 19:37pm
v3
Comments
Richard MacCutchan 7-Feb-17 8:11am    
Solution to what? We have no idea what your code does, where the "page" comes from or what it contains, where the serial number is generated, etc.

Please edit your question and add some proper details.
Member 12986818 17-Feb-17 7:17am    
Sir, Can you give code for above problem?
Member 12986818 23-Feb-17 2:07am    
sir, Is is possible to give changes in above code only?

1 solution

In a multi-user environment, more than one users could end up with the same number if you are using
Select max(`Enquiry No`) as max from enquiry 
. Instead, check out this approach[^].
 
Share this answer
 
Comments
Maciej Los 23-Feb-17 2:43am    
5ed!
Peter Leow 23-Feb-17 3:18am    
Thank you, Maciej.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900