//转换的方法 public List convertList(ResultSet rs) throws SQLException { List list = new ArrayList(); ResultSetMetaData md = rs.getMetaData(); int columnCount = md.getColumnCount(); // Map rowData; while (rs.next()) { // rowData = new HashMap(columnCount); Map rowData = new HashMap(); for (int i = 1; i <= columnCount; i++) { rowData.put(md.getColumnName(i), rs.getObject(i)); } list.add(rowData); } return list; } 调用的函数public String viewListByUser() { System.out.println("access datebase"); Statement pre = null;
try { pre = this.getConnection(); ResultSet re=pre.executeQuery("select * from news where yiid='综合新闻' order by newstime desc"); oThesis = this.convertList(re); String str = oThesis.get(1).toString(); System.out.println(oThesis.size()); // System.out.println("str="+str);
有add方法就有get方法啊如果问题是“如何输出到页面”,
个人意见:希望lz补足一下基础知识,再有不懂的再来发贴问good luck
public List convertList(ResultSet rs) throws SQLException {
List list = new ArrayList();
ResultSetMetaData md = rs.getMetaData();
int columnCount = md.getColumnCount(); // Map rowData;
while (rs.next()) { // rowData = new HashMap(columnCount);
Map rowData = new HashMap();
for (int i = 1; i <= columnCount; i++) {
rowData.put(md.getColumnName(i), rs.getObject(i));
}
list.add(rowData);
}
return list;
}
调用的函数public String viewListByUser() {
System.out.println("access datebase");
Statement pre = null;
try {
pre = this.getConnection();
ResultSet re=pre.executeQuery("select * from news where yiid='综合新闻' order by newstime desc");
oThesis = this.convertList(re);
String str = oThesis.get(1).toString();
System.out.println(oThesis.size());
// System.out.println("str="+str);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} return SUCCESS; }
输出的结果是access datebase
con=sun.jdbc.odbc.JdbcOdbcConnection@16672d6
327
str={newstime=2011-10-14 10:51:16.0, shoupic=, yiid=综合新闻, recommend=null, id=715, Audit=true, title=离退休干部服务处举办《老年人体育锻炼及注意事项》专, hit=129, daodu=, erid=0, xiazai=false, paixu=715}
怎样取某一个字段的值,如title=“”;只取出一个来 怎么取啊