posts - 165, comments - 198, trackbacks - 0, articles - 1
  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理
代码上了 ----
            Collection list = new ArrayList();
            ApplicationsBean applications 
= null;
            ResultSet rs
=null;
            DBConn db
=null;
        
            
try {
                db
=new DBConn();
        
          String sql 
= "select * from (select rownum row_id,b.* from (select a.* from jcyy.vbasepersonnel a)b) where row_id between "+sta+" and "+end;
          
          rs
=db.executeQuery(sql);
          ResultSetMetaData md 
= rs.getMetaData() ;
          
int col = md.getColumnCount() ; 
          
          
int[] type = new int[col+1];
          
for(int i=1;i<=col;i++){
              type[i] 
= md.getColumnType(i);
          }
          String[] colNames 
= new String[col+1];
          
for(int i=1;i<=col;i++){
              colNames[i
-1= md.getColumnName(i).trim();
          }
          
          Hashtable map 
= new Hashtable();  
          Method[] mes 
=  Vbasepersonnel.class.getMethods() ;
              
for(int i=0; i<mes.length;i++){
                String setName 
= mes[i].getName().trim();    
                
if(setName.indexOf("set")==0){
                    String name 
= setName.substring(3,setName.length()).toUpperCase();
                    map.put(name,mes[i]);
                }
            }
            
              

                  
while (rs.next()) {
                      Vbasepersonnel vb 
= new Vbasepersonnel();
                      
                      
for(int i=1;i<=col;i++){
                          
                          
if(colNames[i] == nullcontinue ;//个别的可 另拿出来 if colNames == NN  ->  rs.getXXXX()
                          
                          Method me 
= (Method)map.get( colNames[i] );
                          
if(me != null){
                              
try{
                              
if(type[i]==java.sql.Types.DATE)    me.invoke(vb,new Object[]{rs.getDate(colNames[i])});
                              
if(type[i]==java.sql.Types.INTEGER)    me.invoke(vb,new Object[]{new Integer(rs.getInt(colNames[i]))});
                              
//if(type[i]==java.sql.Types.BIGINT)    me.invoke(vb,new Object[]{rs.getBigDecimal(colNames[i])});
                              if(type[i]==java.sql.Types.DOUBLE)    me.invoke(vb,new Object[]{new Double(rs.getDouble(colNames[i]))});
                              
if(type[i]==java.sql.Types.FLOAT)    me.invoke(vb,new Object[]{new Float(rs.getFloat(colNames[i]))});
                              
if(type[i]==java.sql.Types.BOOLEAN)    me.invoke(vb,new Object[]{new Boolean(rs.getBoolean(colNames[i]))});
                              
if(type[i]==java.sql.Types.LONGVARBINARY)    me.invoke(vb,new Object[]{new Long(rs.getLong(colNames[i]))});
                              
if(type[i]==java.sql.Types.BOOLEAN)     me.invoke(vb,new Object[]{new Boolean(rs.getBoolean(colNames[i]))});
                              
                              
else    me.invoke(vb,new Object[]{rs.getObject(colNames[i])});
                              }
catch(Exception ex){
                                  System.out.println(colNames[i]
+"XX"+type[i]);
                                  colNames[i] 
= null ;
                              }
                          }
                      }
                      
                      list.add(vb);
                }




只有注册用户登录后才能发表评论。


网站导航: