⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 corporationdao.java

📁 这个程序是花了好几十万请人开发的
💻 JAVA
字号:
package javabean;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import javabean.CodeString;
import struts.form.*;

public class CorporationDAO {
	
	private static Connection con;
	
	public CorporationDAO(Connection con)
	{
		CorporationDAO.con=con;
	}

	public void create(Corporation corporation) throws CreateException{
    	
		PreparedStatement ps=null;
		ResultSet rs=null;
		String sqlmax="select max(ID) as n from CORPORATION";
		String sql="INSERT INTO CORPORATION VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
      
		try
		{			
			if(con.isClosed())
			{
				throw new IllegalStateException("error.unexpected");    
			}
			ps=con.prepareStatement(sqlmax);
			rs=ps.executeQuery();
			int Id=0;
			String bothday="";
			
			while(rs.next())
			{
				Id=rs.getInt("n");
				Id=Id+1;
			}
			
			CodeString getstring=new CodeString();
			if(corporation.getCORPDATE()!=""){
				bothday=getstring.getString(corporation.getCORPDATE())+'年';
			}
						
			PubDate pubDate=new PubDate();
			String pbdate=pubDate.getshortPubdate();
        	
        	TextareaChange change=new TextareaChange();
        	String corpmemo=getstring.getString(change.changeArea(corporation.getCORPMEMO()));
        	
			ps=con.prepareStatement(sql);
			ps.setInt(1,Id);
			ps.setString(2,getstring.getString(corporation.getUUID()));
			ps.setString(3,getstring.getString(corporation.getCORPNAME()));
			ps.setString(4,getstring.getString(corporation.getCORPCATE()));
			ps.setString(5,getstring.getString(corporation.getCORPTYPE()));
			ps.setString(6,corpmemo);
			ps.setString(7,bothday);
			ps.setString(8,getstring.getString(corporation.getCORPMONEY()));
			ps.setString(9,getstring.getString(corporation.getCORPEMPL()));
			ps.setString(10,getstring.getString(corporation.getCONTNAME()));
			ps.setString(11,getstring.getString(corporation.getCORPPHONE()));
			ps.setString(12,getstring.getString(corporation.getCORPFAX()));
			ps.setString(13,getstring.getString(corporation.getCORPADDR()));
			ps.setString(14,getstring.getString(corporation.getCORPWEB()));
			ps.setString(15,getstring.getString(corporation.getCORPEMAIL()));
			ps.setString(16,getstring.getString(corporation.getCORPZIP()));
			ps.setString(17,pbdate);
			
			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 Corporation findByPrimaryKey(String user)
		throws FinderException{
    	
			PreparedStatement ps=null;
			ResultSet rs=null;
			Corporation corporation=null;
		
			String sql="SELECT * from CORPORATION WHERE UUID="+"'"+user+"'";
		
			try{
				if(con.isClosed()){
					throw new IllegalStateException("error.unexpected");    
				}
			
				ps=con.prepareStatement(sql);
				//ps.setString(1,user);
				rs=ps.executeQuery();
			
				if(rs.next()){
				
					corporation=new Corporation();
					corporation.setID(rs.getInt(1));		
					corporation.setUUID(rs.getString(2));	
					corporation.setCORPNAME(rs.getString(3));		
					corporation.setCORPCATE(rs.getString(4));	
					corporation.setCORPTYPE(rs.getString(5));	
					corporation.setCORPMEMO(rs.getString(6));	
					corporation.setCORPDATE(rs.getString(7));
					corporation.setCORPMONEY(rs.getString(8));
					corporation.setCORPEMPL(rs.getString(9));
					corporation.setCONTNAME(rs.getString(10));		
					corporation.setCORPPHONE(rs.getString(11));	
					corporation.setCORPFAX(rs.getString(12));	
					corporation.setCORPADDR(rs.getString(13));	
					corporation.setCORPWEB(rs.getString(14));	
					corporation.setCORPEMAIL(rs.getString(15));
					corporation.setCORPZIP(rs.getString(16));
					corporation.setFBTIME(rs.getString(17));
					
					return corporation;
				}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 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 + -