我想在NetBeans中将类似”S1001″的字符串ID增加到”S1002″。

huangapple 未分类评论42阅读模式
英文:

i want to increase string ID like "S1001" to "S1002" in netbeans

问题

当我按下新ID按钮时,我想要增加到"S1004"并显示在文本字段中,我想从数据库中获取最后一个ID,我该如何做到这一点?

英文:

check image for information

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

huangapple
  • 本文由 发表于 2020年4月4日 23:27:48
  • 转载请务必保留本文链接:https://java.coder-hub.com/61030408.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定