通过spring+hibernate返回一个collection呀。public Collection GetYgdm() throws DataAccessException {
return getHibernateTemplate()
.find(
""
+ "select new com.irtn.emp(ygdm,ksdm,ygxm,pydm) from emp ");
}
return getHibernateTemplate()
.find(
""
+ "select new com.irtn.emp(ygdm,ksdm,ygxm,pydm) from emp ");
}
XML的格式是定义好的
看我的这个 是不是不行呢
public Collection<Object> getExe(String sql){
ArrayList arrResultSet=new ArrayList();
try{
InputStream in = getClass().getResourceAsStream("/jdbc.properties");
Properties properties = new Properties();
properties.load(in);
String driver = properties.getProperty("jdbc.driverClassName");
String url = properties.getProperty("jdbc.url");
String user = properties.getProperty("jdbc.username");
String password = properties.getProperty("jdbc.password");
Class.forName(driver);
Connection conn=DriverManager.getConnection(url, user, password);
ResultSet rs=conn.createStatement().executeQuery(sql);
ResultSetMetaData rsmd=rs.getMetaData();
int cols=rsmd.getColumnCount();
while (rs.next()) {
ArrayList row=new ArrayList();
for (int i=1;i<=cols;i++) {
String cname= rsmd.getColumnName(i);
row.add(rs.getObject(cname));
}
arrResultSet.add(row);
}
rs.close();
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
} catch (SQLException ex) {
ex.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return arrResultSet;
}
ArrayList arrResultSet=new ArrayList();
try{
InputStream in = getClass().getResourceAsStream("/jdbc.properties");
Properties properties = new Properties();
properties.load(in);
String driver = properties.getProperty("jdbc.driverClassName");
String url = properties.getProperty("jdbc.url");
String user = properties.getProperty("jdbc.username");
String password = properties.getProperty("jdbc.password");
Class.forName(driver);
Connection conn=DriverManager.getConnection(url, user, password);
ResultSet rs=conn.createStatement().executeQuery(sql);
ResultSetMetaData rsmd=rs.getMetaData();
int cols=rsmd.getColumnCount();
while (rs.next()) {
ArrayList row=new ArrayList();
for (int i=1;i<=cols;i++) {
String cname= rsmd.getColumnName(i);
row.add(rs.getObject(cname));
}
arrResultSet.add(row);
}
rs.close();
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
} catch (SQLException ex) {
ex.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return arrResultSet;
}