[英]How to make id with text auto increment in java?
I want to select data from mysql and input into JComboBox as an auto increment. 我想从mysql中选择数据并将其作为自动增量输入到JComboBox中。
DefaultComboBoxModel mo = new DefaultComboBoxModel();
try {
rs = stmt.executeQuery("select pid from tbpatient");
while(rs.next()) {
mo.addElement(rs.getString(1));
}
} catch(SQLException e) {
e.printStackTrace();
}
jComboBox1.setModel(mo);
} }
But I want my text show "P001" and auto increment. 但是我想让我的文字显示“ P001”并自动递增。
What you could do is store the key as two columns. 您可以将密钥存储为两列。 A char prefix and an auto-incrementing int, both of which are grouped for the primary key. 一个char前缀和一个auto-incrementing int,它们都被分组为主键。
CREATE TABLE myItems (
id INT NOT NULL AUTO_INCREMENT,
prefix CHAR(30) NOT NULL,
PRIMARY KEY (id, prefix),
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.