|
没想到才开始做JSP,难题又出现了.
我在做完登录检查,如果正确,就转到欢迎页面,在欢迎页面里我想让它显示新闻消息.
为了动态,我把新闻消息在做在一个数据表里,然后从数据厍读出来显示.代码如下:
- String newsInfo=null;
- Connection conn2=null;
- Statement stmt=null;
- try
- {
- Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
- conn2= DriverManager.getConnection("jdbc:odbc:Test","sa","");
- stmt=conn2.createStatement();
- ResultSet rs=stmt.executeQuery("select * from news");
- while(rs.next()){
- String title=rs.getString("title");
- newsInfo=title;
- stmt.close();
- conn2.close();
- }
- }catch(Exception ex)
- {
- if(stmt!=null)stmt.close();
- if(conn2!=null)conn2.close();
- String errorMsg=ex.getMessage();
- newsInfo=new String(errorMsg.getBytes("GBK"),"ISO-8859-1");
- }
- %>
- <table><%=newsInfo%></table>
复制代码
可是,一执行起来,newsInfo总是"ResultSet is closed".我根本提前没关闭过它.真是百思不解.唯一关闭过的是上一个页面的conn.(注:登录处理的代码在"JSP入门一例"那个帖里)
我百度过了,好像很多人都有遇过这样的问题.可我就是没有找到解决方法.如果你知道,请告诉我!先谢谢了! |
|