Person.java
None.gif
None.gif
ExpandedBlockStart.gifContractedBlock.gif
/**/ /*
InBlock.gif * 创建日期 2005-3-17
InBlock.gif *
InBlock.gif * 
InBlock.gif * 
ExpandedBlockEnd.gif 
*/

None.gifpackage com.faintbear;
None.gif
ExpandedBlockStart.gifContractedBlock.gif
/**/ /**
InBlock.gif * 
InBlock.gif *
InBlock.gif * 
InBlock.gif * 
ExpandedBlockEnd.gif 
*/

ExpandedBlockStart.gifContractedBlock.gif
public   class  Person  dot.gif {
InBlock.gif 
InBlock.gif   
private  String empname="";
InBlock.gif   
private  String empno="";
InBlock.gif   
InBlock.gif  
public void setEmpName(String empname)
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif     
this.empname=empname;
ExpandedSubBlockEnd.gif  }

InBlock.gif  
InBlock.gif  
public String getEmpName()
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif    
return this.empname;
ExpandedSubBlockEnd.gif  }

InBlock.gif  
InBlock.gif  
InBlock.gif  
public void setEmpNo(String empno)
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif      
this.empno=empno;
ExpandedSubBlockEnd.gif  }

InBlock.gif  
InBlock.gif  
public String getEmpNo()
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif     
return this.empno;
ExpandedSubBlockEnd.gif  }

InBlock.gif 
InBlock.gif
ExpandedBlockEnd.gif}

None.gif
None.gif
None.gif
None.gif
None.gifDbConnect.java
None.gif
None.gifpackage com.faintbear;
None.gifimport java.util.
* ;
None.gifimport java.sql.
* ;
None.gif
ExpandedBlockStart.gifContractedBlock.gif
/**/ /**
InBlock.gif * 
InBlock.gif *
InBlock.gif * 数据库连接和测试
InBlock.gif * 
ExpandedBlockEnd.gif 
*/

ExpandedBlockStart.gifContractedBlock.gif
public   class  DbConnect  dot.gif {
InBlock.gif    
InBlock.gif    
public Connection conn;
InBlock.gif    
private Statement stmt;
InBlock.gif    
private PreparedStatement pstmt;
InBlock.gif    
InBlock.gif    
private String dburl="jdbc:oracle:thin:@192.168.41.16:1521:cc";
InBlock.gif    
private String user="cc";
InBlock.gif    
private String password="123456";
InBlock.gif    
private String driver="oracle.jdbc.driver.OracleDriver";
InBlock.gif    
InBlock.gif    
InBlock.gif    
InBlock.gif    
public DbConnect() throws Exception
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif      Class.forName(driver);
InBlock.gif      conn 
=DriverManager.getConnection(dburl,user,password);
InBlock.gif      stmt 
= conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
InBlock.gif    
InBlock.gif      
ExpandedSubBlockEnd.gif    }

InBlock.gif    
InBlock.gif    
public Connection getConnection()
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif      
return conn;
ExpandedSubBlockEnd.gif    }

InBlock.gif    
InBlock.gif    
InBlock.gif   
public List getEmpNameList() throws Exception 
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{
InBlock.gif      String sql
="select * from cus_emp_basic where rownum<10";
InBlock.gif      Connection conn
=null;
InBlock.gif      Statement stmt
=null;
InBlock.gif      ResultSet rst
=null;
InBlock.gif      ArrayList resultlist 
= new ArrayList();
InBlock.gif      
try
ExpandedSubBlockStart.gifContractedSubBlock.gif      
dot.gif{
InBlock.gif          
InBlock.gif          rst
=(new DbConnect()).stmt.executeQuery(sql);
InBlock.gif          
InBlock.gif          
while (rst.next())
ExpandedSubBlockStart.gifContractedSubBlock.gif          
dot.gif{
InBlock.gif            Person person 
= new Person();
InBlock.gif            person.setEmpNo(rst.getString(
"emp_no"));
InBlock.gif            person.setEmpName(rst.getString(
"emp_name"));
InBlock.gif            resultlist.add(person);
ExpandedSubBlockEnd.gif          }

ExpandedSubBlockEnd.gif      }
finally
ExpandedSubBlockStart.gifContractedSubBlock.gif      
dot.gif{
InBlock.gif       
if(rst!=null)rst.close();
InBlock.gif       
if(stmt!=null)stmt.close();
InBlock.gif       
if(conn!=null)conn.close();
ExpandedSubBlockEnd.gif      }

InBlock.gif      
InBlock.gif      
return resultlist;
InBlock.gif      
InBlock.gif      
ExpandedSubBlockEnd.gif   }

InBlock.gif   
InBlock.gif   
public static void main(String []args) throws Exception
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{
InBlock.gif         DbConnect dbc 
= new DbConnect();
InBlock.gif        List l1
=(dbc.getEmpNameList());
InBlock.gif         
for(int i=0;i<l1.size();i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif         
dot.gif{
InBlock.gif          Person person1
=(Person)l1.get(i);
InBlock.gif          System.
out.println("person"+i+"="+person1.getEmpName()+" "+"empno="+person1.getEmpNo());
InBlock.gif          
ExpandedSubBlockEnd.gif         }

InBlock.gif        
InBlock.gif        
ExpandedSubBlockEnd.gif   }

InBlock.gif
ExpandedBlockEnd.gif}