在java eclipse中生成自动增量序列号 [英] Generate auto increment serial number in java eclipse
问题描述
我在java中设计了一个表单,其中textfield就在那里。所以我想在这个文本字段中显示序列号...意味着当前的文本字段值应该是1 ..然后我将填写这些表单并提交...我将回来文本值应该是2 ...提交此表单后,textfield值变为3等等......那么如何在JTextfield中自动增加序列号和显示...
我尝试了什么:
这里我使用了java eclipse和sqlite数据库。
我试过以下代码
textField = new JTextField();
试试
{
字符串查询=选择最大值(`查询号码)作为查询的最大值;
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(例外a)
{
a.printStackTrace();
}
在一个多 - 用户环境,如果您使用选择最大值(查询号码)作为查询的最大值
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();
}
In a multi-user environment, more than one users could end up with the same number if you are usingSelect max(`Enquiry No`) as max from enquiry
这篇关于在java eclipse中生成自动增量序列号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!