我正在尝试将数据从 Mysql db 获取到 .jsp 页面:
<%
List list = connection.getBookList();
int id = 0;
String box = null;
Iterator<String> it = list.iterator();
while (it.hasNext()) {
id = Integer.parseInt(it.next());
out.print("<tr>");
for (int i = 0; i < 4; i++) {
out.print("<td>");
out.print(it.next());
out.print("</td>");
}
out.print("<td>");
box = "<input name=r" + id + " type='checkbox'>";
out.print(box);
out.print("</td>");
out.print("</tr>");
}
%>
这是我的数据库检索类中的方法:
public List getBookList() throws SQLException
{
List BookList = new ArrayList();
ResultSet results = statement.executeQuery("SELECT * FROM book" );
while ( results.next() ) {
BookBean view = new BookBean();
view.setID(results.getString( 1 ));
view.setName(results.getString( 2 ));
view.setDescription(results.getString( 3));
view.setCatID(results.getString( 4));
view.setUID(results.getString(5 ));
view.setDateAdded(results.getString( 6 ));
view.setPicThumb(results.getString( 7 ));
view.setPicLarge(results.getString( 8 ));
BookList.add(view);
}
return BookList;
}
如果以上面方法的编写方式在jsp页面中打印我的数据有什么帮助吗?我认为(视图)有所不同,不是吗?