插入数据时如何在文本框中显示自动增量
问题描述:
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.