📄 empadddao.java
字号:
package com.isoftstone.banktearm1.dao;
import java.sql.*;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.StringTokenizer;
import com.isoftstone.banktearm1.db.*;
import com.isoftstone.banktearm1.vo.BankTeam1EmpVo;
import com.isoftstone.banktearm1.vo.BankTeam1EmpVo2;
//添加vo到emp表中
public class EmpAddDao extends DB {
public void insertRecort(BankTeam1EmpVo2 myvo) throws Exception{
int i=0;
String sql="insert into emp values("+this.SelectRecort()+","+myvo.getWorkerId()+",'"+myvo.getName()+"','"+myvo.getSex()+"','"+myvo.getBirthday()+"','"+myvo.getDepartment()+"','"+myvo.getJobName()+"','"+myvo.getPassword()+"')";
Connection cn= this.getConnection();
Statement stmt=cn.createStatement();
i=stmt.executeUpdate(sql);
if(stmt!=null){
stmt.close();
}
if(cn!=null){
cn.close();
}
}
public int SelectRecort() throws SQLException, ClassNotFoundException{
int i=0;
Connection cn= this.getConnection();
Statement stmt=cn.createStatement();
String sql="select max(id) from emp";
ResultSet rs=stmt.executeQuery(sql);
if(rs.next()){
i=rs.getInt(1)+1;
}
if(rs!=null){rs.close();}
if(stmt!=null){stmt.close();}
if(cn!=null){cn.close();};
return i;
}
public int getNextWorkId(String st)throws Exception{
Connection cn= this.getConnection();
Statement stmt=cn.createStatement();
String sql="select cstr(max(mid(cstr(WorkerID),5,6))) as a from emp";
ResultSet rs = stmt.executeQuery(sql);
rs.next();
String maxid=rs.getString("a");
int maxid2=Integer.parseInt(maxid)+1;
if(maxid2<10){
maxid="0"+String.valueOf(maxid2);
}
else{
maxid=String.valueOf(maxid2);
}
String workId=st+maxid;
if(stmt!=null){
stmt.close();
}
if(cn!=null){
cn.close();
}
return Integer.parseInt(workId);
}
//
// public int grewWorkID(String st) throws Exception{
// int i = this.getNextWorkId(st);
// int index=0;
// Connection cn= this.getConnection();
// Statement stmt=cn.createStatement();
// String sql="SELECT WorkerID from emp";
// ResultSet rs = stmt.executeQuery(sql);
// while(rs.next()){
// index = rs.getInt("WorkerID");
// }
// index++;
// String s = index+"";
//
//
// return Integer.parseInt(i+s.substring(4, s.length()));
// }
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -