英文:
i want to increase string ID like "S1001" to "S1002" in netbeans
问题
当我按下新ID按钮时,我想要增加到"S1004"并显示在文本字段中,我想从数据库中获取最后一个ID,我该如何做到这一点?
英文:
im using netbeans javaDB.
when i press the new id button, i want to increase to "S1004" and show in text field
i want get last id from database
how can i do that?
答案1
得分: 0
我想将字符串ID从“S1001”增加到“S1002”
这将适用于您的示例
String id = "S1001";
String num = id.substring(1); // 删除第一个字符
int num = Integer.parseInt(num) + 1; // 转换为整数并增加
id = ("S" + num); // 转换回来
英文:
i want to increase string ID like “S1001” to “S1002”
This will work for your example
String id = "S1001";
String num = id.substring(1); // remove first char
int num = Integer.parseInt(num) + 1; // convert to int and increment
id = ("S" + num); // convert it back
专注分享java语言的经验与见解,让所有开发者获益!
评论