1 package jodd.bean.loaders; 2 3 import java.sql.ResultSet; 4 import java.sql.ResultSetMetaData; 5 import java.sql.SQLException; 6 import java.util.StringTokenizer; 7 8 import jodd.bean.BeanUtil; 9 10 13 public class ResultSetLoader implements jodd.bean.Loader { 14 15 public void load(Object bean, Object rs) { 16 if (rs instanceof ResultSet) { 17 try { 18 ResultSetMetaData rsmd = ((ResultSet)rs).getMetaData(); 19 int numberOfColumns = rsmd.getColumnCount(); 20 for (int i = 1; i <= numberOfColumns; i++) { 21 StringTokenizer st = new StringTokenizer(rsmd.getColumnName(i), "_"); 22 StringBuffer columnName = new StringBuffer(); 23 while (st.hasMoreTokens()) { 24 String token = st.nextToken().toLowerCase(); 25 columnName.append(token.substring(0, 1).toUpperCase()).append(token.substring(1)); 26 } 27 BeanUtil.setProperty(bean, columnName.toString(), ((ResultSet)rs).getObject(i)); 28 } 29 } catch (SQLException sex) { 30 } catch (Exception ex) { 31 } 32 } 33 return; 34 } 35 } 36 37 | Popular Tags |