您的位置:首页 > 其它

员工编号总共6位,由字母XD+4位数字编号组成(如XD0001) * 必须唯一,在新增时自动生成,数字编号自动增长。在修改时,员工编号无法修改。

2018-01-22 17:15 323 查看
public String getEmployeeid() {
Connection con = new JDBCUtil().getConnection();
String id = null;
String sql = "select * from employeebasicinfo order by employeeid desc limit 1";
PreparedStatement pstOne = null;
ResultSet rs = null;
try {
pstOne = con.prepareStatement(sql);
rs = pstOne.executeQuery();

if (rs.next()) {
String a = rs.getString("employeeid");
int idnum = 0;
try {
idnum = Integer.parseInt(a.substring(a.length() - 4)) + 1;
} catch (NumberFormatException e) {
e.printStackTrace();
}
DecimalFormat df = new DecimalFormat("0000");
String aa = df.format(idnum);
id = "XD"  + aa;
} else {
id = "XD" + "0000";
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
rs.close();
pstOne.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
return id;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐