插入数据时如何在文本框中显示自动增量 [英] how to display auto increment in textbox when inserting a data
本文介绍了插入数据时如何在文本框中显示自动增量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
try
{
String query="insert into category_2 (catname)values(?)";
pst=conn.prepareStatement(query);
pst.setString(1,jTextField18.getText());
pst.execute();
JOptionPane.showMessageDialog(null,"Category Added Sucessfully");
pst.close();
} catch (Exception e1)
{
e1.printStackTrace();
}
推荐答案
所以你添加了catagory字段。如果表category_2
具有自动字段且catname
具有唯一索引,则可以继续查询该表;很难知道。如果没有,那么你需要从某个地方获取价值。如果它是catagories的总数,则从category_2
中选择count(catname)是您需要的查询,否则您可以在代码中生成该数字。
So you add the catagory field. If the tablecategory_2
has an auto field andcatname
has a unique index, then you could continue by querying the table; hard I know. If not then you need to get the value from somewhere. If it is the total number of catagories thenselect count(catname) from category_2
is the query you need or else you could generate the number in your code.
这篇关于插入数据时如何在文本框中显示自动增量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文