流水号的简单自动生成
一、字母KC+4位数字编号组成必须唯一,在新增时自动生成,数字编号自动增长
/**
* 自动生成课程表ID => 字母KC+4位数字编号组成(如KC0001)
* @return
*/
public String getCourseinfoId(){
Connection conn = null;
PreparedStatement pstm = null;
ResultSet rs = null;
String id = null;
String sql = "select * from courseinfo order by id desc limit 1";
try {
conn = JDBCUtil.getConnection();
pstm = conn.prepareStatement(sql);
rs = pstm.executeQuery();
if(rs.next()){
String a = rs.getString("id");
int idnum = 0;
idnum = Integer.parseInt(a.substring(a.length() - 4)) + 1;
DecimalFormat df = new DecimalFormat("0000");
String aa = df.format(idnum);
id = "KC" + aa;
}else{
id = "KC" + "0001"; //从 KC0001 开始
}
} catch (SQLException e) {
e.p