- UID
- 89114
- 帖子
- 101
- 积分
- 3898
- 阅读权限
- 50
- 注册时间
- 2008-8-31
- 最后登录
- 2014-6-30
- 在线时间
- 777 小时
|
流水号我觉得用日期的方式比较好,比如2008年9月21日第一个号就是200809210001
public String genVouNo() throws Exception {
//格式化今天的日期
String currentDate = new SimpleDateFormat("yyyyMMdd").format(new Date());
//找到表中今天最大的单号的sql语句
String sql = "select max(vou_no) from t_flow_card_master where substr(vou_no, 1, 8)='" + currentDate + " ' ";
PreparedStatement pstmt = null;
ResultSet rs = null;
Connection conn = null;
String vouNo = currentDate + "0001";
try {
//建立数据库连接
conn = DriverManager.getConnection("连接access数据库字符串");
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
//得到结果集
rs.next();
//当结果不为空时,让单号+1
if (rs.getLong(1) != 0) {
vouNo = String.valueOf((rs.getLong(1) + 1));
}
//捕捉异常
}catch(Exception e) {
e.printStackTrace();
throw new Exception("生成单号失败:" +e);
//关闭数据库连接
}finally {
rs.close();
pstmt.close();
conn.close();
}
//返回单号
return vouNo;
然后调用这个方法,把得到的单号存到相应的流向单就行了 |
|