📄 zwxxdao.java
字号:
package javabean;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Collection;
import java.util.ArrayList;
import java.util.Vector;
import struts.form.*;
import javabean.CodeString;
public class ZwxxDAO {
private static Connection con;
public ZwxxDAO(Connection con)
{
ZwxxDAO.con=con;
}
public void create(Zwxx zwxx) throws CreateException{
PreparedStatement ps=null;
ResultSet rs=null;
String sqlmax="select max(ID) as n from ZWXX";
String sql="INSERT INTO ZWXX VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
try{
if(con.isClosed())
{
throw new IllegalStateException("error.unexpected");
}
ps=con.prepareStatement(sqlmax);
rs=ps.executeQuery();
int Id=0;
String pbdate="";
while(rs.next())
{
Id=rs.getInt("n");
Id=Id+1;
}
CodeString getstring=new CodeString();
PubDate pubDate=new PubDate();
pbdate=pubDate.getshortPubdate();
//换行处理
TextareaChange change=new TextareaChange();
String memo=getstring.getString(change.changeArea(zwxx.getMEMO()));
ps=con.prepareStatement(sql);
ps.setInt(1,Id);
ps.setString(2,getstring.getString(zwxx.getUUID()));
ps.setString(3,getstring.getString(zwxx.getJOBCATE()));
ps.setString(4,getstring.getString(zwxx.getJOBNAME()));
ps.setInt(5,zwxx.getJOBNUM());
ps.setString(6,getstring.getString(zwxx.getPROVINCE()));
ps.setString(7,getstring.getString(zwxx.getWORKMODE()));
ps.setString(8,getstring.getString(zwxx.getWORKMONEY()));
ps.setString(9,getstring.getString(zwxx.getSEX()));
ps.setString(10,getstring.getString(zwxx.getGRADE()));
ps.setString(11,getstring.getString(zwxx.getWORKTIME()));
ps.setString(12,getstring.getString(zwxx.getAGE()));
ps.setString(13,getstring.getString(zwxx.getBORNADDR()));
ps.setString(14,memo);
ps.setString(15,pbdate);
ps.setString(16,getstring.getString(zwxx.getVALIDTIME()));
ps.setInt(17,0);
ps.setString(18,getstring.getString(zwxx.getCLASS()));
ps.setString(19,getstring.getString(zwxx.getLANG()));
if(ps.executeUpdate()!=1)
{
throw new CreateException("error.create.attraction");
}
}
catch(SQLException e)
{
/*try{
findByPrimaryKey(attraction.getUserId());
}catch(FinderException fe){
fe.printStackTrace();
throw new RuntimeException("error.unexpected");
}*/
throw new DuplicateKeyException("error.duplicate.attraction");
}
finally
{
try
{
if(ps!=null) ps.close();
}
catch(SQLException e)
{
e.printStackTrace();
throw new RuntimeException("error.unexpected");
}
}
}
public void update(String sql) throws CreateException{
PreparedStatement ps=null;
try
{
if(con.isClosed())
{
throw new IllegalStateException("error.unexpected");
}
ps=con.prepareStatement(sql);
if(ps.executeUpdate()!=1)
{
throw new CreateException("error.create.attraction");
}
}
catch(SQLException e)
{
e.printStackTrace();
throw new RuntimeException("error.unexpected");
}
finally
{
try
{
if(ps!=null) ps.close();
}
catch(SQLException e)
{
e.printStackTrace();
throw new RuntimeException("error.unexpected");
}
}
}
public static Zwxx findByPrimaryKey(int Id)
throws FinderException{
PreparedStatement ps=null;
ResultSet rs=null;
Zwxx zwxx=null;
String sql="SELECT * from ZWXX WHERE ID=?";
try
{
if(con.isClosed())
{
throw new IllegalStateException("error.unexpected");
}
ps=con.prepareStatement(sql);
ps.setInt(1,Id);
rs=ps.executeQuery();
if(rs.next())
{
zwxx=new Zwxx();
zwxx.setID(rs.getInt(1));
zwxx.setUUID(rs.getString(2));
zwxx.setJOBCATE(rs.getString(3));
zwxx.setJOBNAME(rs.getString(4));
zwxx.setJOBNUM(rs.getInt(5));
zwxx.setPROVINCE(rs.getString(6));
zwxx.setWORKMODE(rs.getString(7));
zwxx.setWORKMONEY(rs.getString(8));
zwxx.setSEX(rs.getString(9));
zwxx.setGRADE(rs.getString(10));
zwxx.setWORKTIME(rs.getString(11));
zwxx.setAGE(rs.getString(12));
zwxx.setBORNADDR(rs.getString(13));
zwxx.setMEMO(rs.getString(14));
zwxx.setFBTIME(rs.getString(15));
zwxx.setVALIDTIME(rs.getString(16));
zwxx.setCLICKNUM(rs.getInt(17));
zwxx.setCLASS(rs.getString(18));
zwxx.setLANG(rs.getString(19));
return zwxx;
}
else
{
throw new ObjectNotFoundException("error.removed.attraction");
}
}
catch(SQLException e)
{
e.printStackTrace();
throw new RuntimeException("error.unexpected");
}
finally
{
try
{
if(ps!=null) ps.close();
if(rs!=null) rs.close();
}
catch(SQLException e)
{
e.printStackTrace();
throw new RuntimeException("error.unexpected");
}
}
}
public Collection findAll(String sql){
PreparedStatement ps=null;
ResultSet rs=null;
ArrayList list=new ArrayList();
try
{
if(con.isClosed())
{
throw new IllegalStateException("error.unexpected");
}
ps=con.prepareStatement(sql);
rs=ps.executeQuery();
while(rs.next())
{
Zwxx zwxx=new Zwxx();
zwxx.setID(rs.getInt(1));
zwxx.setUUID(rs.getString(2));
zwxx.setJOBCATE(rs.getString(3));
zwxx.setJOBNAME(rs.getString(4));
zwxx.setJOBNUM(rs.getInt(5));
zwxx.setPROVINCE(rs.getString(6));
zwxx.setWORKMODE(rs.getString(7));
zwxx.setWORKMONEY(rs.getString(8));
zwxx.setSEX(rs.getString(9));
zwxx.setGRADE(rs.getString(10));
zwxx.setWORKTIME(rs.getString(11));
zwxx.setAGE(rs.getString(12));
zwxx.setBORNADDR(rs.getString(13));
zwxx.setMEMO(rs.getString(14));
zwxx.setFBTIME(rs.getString(15));
zwxx.setVALIDTIME(rs.getString(16));
zwxx.setCLICKNUM(rs.getInt(17));
zwxx.setCLASS(rs.getString(18));
zwxx.setLANG(rs.getString(19));
zwxx.setCORPNAME(rs.getString(20));
list.add(zwxx);
}
return list;
}
catch(SQLException e)
{
e.printStackTrace();
throw new RuntimeException("error.unexpected");
}
finally
{
try
{
if(ps!=null) ps.close();
if(rs!=null) rs.close();
}
catch(SQLException e)
{
e.printStackTrace();
throw new RuntimeException("error.unexpected");
}
}
}
public Vector find_fenye(int code,int pagesize,String str){
PreparedStatement ps=null;
ResultSet rs=null;
Vector vec=new Vector();
try
{
if(con.isClosed())
{
throw new IllegalStateException("error.unexpected");
}
int count=pagesize;
rs=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY).executeQuery(str);
rs.absolute((code-1)*pagesize+1);
while(count>0)
{
Zwxx zwxx=new Zwxx();
zwxx.setID(rs.getInt(1));
zwxx.setUUID(rs.getString(2));
zwxx.setJOBCATE(rs.getString(3));
zwxx.setJOBNAME(rs.getString(4));
zwxx.setJOBNUM(rs.getInt(5));
zwxx.setPROVINCE(rs.getString(6));
zwxx.setWORKMODE(rs.getString(7));
zwxx.setWORKMONEY(rs.getString(8));
zwxx.setSEX(rs.getString(9));
zwxx.setGRADE(rs.getString(10));
zwxx.setWORKTIME(rs.getString(11));
zwxx.setAGE(rs.getString(12));
zwxx.setBORNADDR(rs.getString(13));
zwxx.setMEMO(rs.getString(14));
zwxx.setFBTIME(rs.getString(15));
zwxx.setVALIDTIME(rs.getString(16));
zwxx.setCLICKNUM(rs.getInt(17));
zwxx.setCLASS(rs.getString(18));
zwxx.setLANG(rs.getString(19));
zwxx.setCORPNAME(rs.getString(20));
vec.add(zwxx);
count--;
if(!rs.next())break;
}
return vec;
}
catch(SQLException e)
{
e.printStackTrace();
throw new RuntimeException("error.unexpected");
}
finally
{
try
{
if(ps!=null) ps.close();
if(rs!=null) rs.close();
}
catch(SQLException e)
{
e.printStackTrace();
throw new RuntimeException("error.unexpected");
}
}
}
public int findNum(String str)
throws FinderException{
PreparedStatement ps=null;
ResultSet rs=null;
try
{
if(con.isClosed())
{
throw new IllegalStateException("error.unexpected");
}
ps=con.prepareStatement(str);
rs=ps.executeQuery();
int Id=0;
while(rs.next())
{
Id=rs.getInt("N");
}
return Id;
}
catch(SQLException e)
{
e.printStackTrace();
throw new RuntimeException("error.unexpected");
}
finally
{
try
{
if(ps!=null) ps.close();
if(rs!=null) rs.close();
}
catch(SQLException e)
{
e.printStackTrace();
throw new RuntimeException("error.unexpected");
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -