📄 corporationbo.java
字号:
package javabean;
import struts.form.*;
import javabean.CorporationDAO;
import javabean.CreateException;
import javabean.FinderException;
import javabean.ConnectionPool;
import java.sql.SQLException;
import java.sql.Connection;
import java.util.Iterator;
public class CorporationBO {
private static ConnectionPool pool;
public CorporationBO() {
pool=ConnectionPool.getInstance();
}
public static void AddCorporation(Corporation corporation)
throws CorporationException{
validateCorporation(corporation);
Connection con=null;
try{
con=pool.getConnection();
CorporationDAO corporationDAO=new CorporationDAO(con);
corporationDAO.create(corporation);
con.commit();
}catch(Exception e) {
try{
if(con!=null){
con.rollback();
throw new CorporationException(e.getMessage());
}
}catch(SQLException sqle){
e.printStackTrace();
throw new RuntimeException("error.unexpected");
}
}finally{
try{
if(con!=null) con.close();
}catch(SQLException sqle){
sqle.printStackTrace();
throw new RuntimeException("error.unexpected");
}
}
}
public void update(String sql,Corporation corporation)
throws CorporationException{
validateCorporation(corporation);
Connection con=null;
try{
con=pool.getConnection();
CpgqDAO cpgqDAO=new CpgqDAO(con);
cpgqDAO.update(sql);
con.commit();
}catch(Exception e) {
try{
if(con!=null){
con.rollback();
throw new CorporationException(e.getMessage());
}
}catch(SQLException sqle){
e.printStackTrace();
throw new RuntimeException("error.unexpected");
}
}finally{
try{
if(con!=null) con.close();
}catch(SQLException sqle){
sqle.printStackTrace();
throw new RuntimeException("error.unexpected");
}
}
}
private static void validateCorporation(Corporation corporation)
throws CorporationException{
Check check=new Check();
if(corporation.getCORPNAME().trim().equals("")){
throw new CorporationException("error.missing.corpname");
}
if(corporation.getCORPADDR().trim().equals("")){
throw new CorporationException("error.missing.corpaddr");
}
if(!(corporation.getCORPDATE().trim().length()==4&&corporation.getCORPDATE().trim().compareTo("1800")>0&&corporation.getCORPDATE().trim().compareTo("2006")<0||corporation.getCORPDATE().trim().equals(""))){
throw new CorporationException("error.err.corpdate");
}
if(corporation.getCORPMEMO().trim().equals("")){
throw new CorporationException("error.missing.corpmemo");
}
if(corporation.getCONTNAME().trim().equals("")){
throw new CorporationException("error.missing.contname");
}
if(corporation.getCORPPHONE().trim().equals("")){
throw new CorporationException("error.missing.corpphone");
}
/*if(check.numberchecked(corporation.getCORPPHONE()).equals("false")){
throw new CorporationException("error.err.corpphone");
}*/
if(corporation.getCORPFAX().trim().equals("")){
throw new CorporationException("error.missing.corpfax");
}
/*if(check.numberchecked(corporation.getCORPFAX()).equals("false")){
throw new CorporationException("error.err.corpfax");
}*/
if(corporation.getCORPZIP().trim().equals("")){
throw new CorporationException("error.missing.corpzip");
}
if(check.numberchecked(corporation.getCORPZIP()).equals("false")){
throw new CorporationException("error.err.corpzip");
}
if(!(check.fenxiEmail(corporation.getCORPEMAIL())==3||corporation.getCORPEMAIL().trim().equals(""))){
throw new CorporationException("error.err.corpemail");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -