在java eclipse中生成自动增量序列号 [英] Generate auto increment serial number in java eclipse

查看:523
本文介绍了在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 using

Select max(`Enquiry No`) as max from enquiry 

. Instead, check out this approach[^].


这篇关于在java eclipse中生成自动增量序列号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆