这程序有值返回吗
public Collection getAllMessages(int pagesize, int page) {// 创建数据库连接对象:
try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e){}
try { Connection con=DriverManager.getConnection("jdbc:odbc:MyDB","","");
Statement stmt = null;
ResultSet rs = null;
// 创建数据记录集对象:
stmt = con.createStatement();
// sql语句:
String sql = "use blog select * from blogmsg order by msg_ID desc limit "
+ (page - 1) * pagesize + "," + pagesize;
// 执行sql语句:
// 执行sql语句,返回一个记录集到rs:
rs = stmt.executeQuery(sql);
Collection c = new ArrayList();
BlogMsg msg = null;
while (rs.next()) {
msg = new BlogMsg();
msg.setmsg_ID(rs.getInt("msg_ID"));
msg.setmsg_title(rs.getString("msg_title"));
msg.setmsg_content(rs.getString("msg_content"));
msg.setauthor(rs.getString("author"));
msg.setmsg_date(rs.getDate("msg_date"));
c.add(msg);
msg = null;
}
return c;
} catch (SQLException sqlExc) {
sqlExc.printStackTrace();
return null;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
[[it] 本帖最后由 随便来一记 于 2008-4-10 00:07 编辑 [/it]]