首页取数据问题,急。 我首页取数据老是取一半自动断了,日志中说数据库连接断开了,我查代码没有断开啊,到页面底部才断开的。麻烦大家帮帮我 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <% try{ JdbcOdbc jdbc = new JdbcOdbc(); conn = jdbc.getConnection(); try{ stat=conn.createStatement(); sql = "select top 6 zs_id,dongtai_id,zs_biaoti from zs_dongtai order by zs_time desc"; res = stat.executeQuery(sql); while (res.next()) { %> <tr> <td width="20" height="19" align="center"><img src="images/top_point.gif" width="2" height="4" alt=""/></td> <td><a href="c_congpanydongxin/<%=res.getString("zs_id").trim()%>/<%=res.getString("dongtai_id")%>.htm" title="<%=res.getString("zs_biaoti")%>" target="_blank"><%if (res.getString("zs_biaoti").length() >14) {%><%=res.getString("zs_biaoti").toString().substring(0, 14) %><%}else{%><%=res.getString("zs_biaoti") %><%} %></a></td> </tr> <%}}catch(Exception e){System.out.println(e.getMessage());}finally{try{res.close();stat.close();}catch(Exception e){}} %><% try{ stat=conn.createStatement(); sql = "select top 12 zs_id,zs_company from zs_zhuce where zs_xianshi='是' order by zs_time desc"; res = stat.executeQuery(sql); int j=0; while (res.next()){ j=++j;%> <tr> <td width="10" height="19" align="center"><img src="images/ico2.gif" alt="" /></td> <td width="155"><a href="comp_companyindex/<%=res.getString("zs_id").trim()%>.htm" title="<%=res.getString("zs_company")%>" target="_blank"><% if (res.getString("zs_company").length() > 12){%><%=res.getString("zs_company").toString().substring(0,12) %><%}else{%><%=res.getString("zs_company") %><%} %> </a></td> </tr> <%if(j==6){%> </table></td> <td width="5" valign="bottom"> </td> <td width="155" valign="bottom"><table width="155" border="0" cellspacing="0" cellpadding="0"> <%}}}catch(Exception e){System.out.println(e.getMessage());}finally{try{res.close();stat.close();}catch(Exception e){}}%>我就这样一直往下取数据,最后conn.close();这样有问题吗? 我本地是没有错的,放到服务器之后,日志中就出现Invalid state, the Connection object is closed.这样的错误首页不是有好多列表要取数据,对吧,取到某个列表时就断了,代码如上 public class JdbcOdbc { private final String driver="net.sourceforge.jtds.jdbc.Driver"; private final String url="jdbc:jtds:sqlserver://localhost:1433/newcsdn"; private final String usename = "sasfsdf"; private final String password = "sfsdf"; private Connection conn = null; public JdbcOdbc() { try { Class.forName(driver); } catch (Exception e) { System.out.println(e.getMessage()); } } public Connection getConnection() { try { conn = DriverManager.getConnection(this.url, this.usename, this.password); } catch (Exception e) { System.out.println(e.getMessage()); } return conn; }}我写了这样一个类进行连接的,要用到的地方调用它 注意这里:<%}}catch(Exception e){System.out.println(e.getMessage());}finally{try{res.close();stat.close();}catch(Exception e){}} %> 把conn也关闭,下面的代码中再重新生成一个conn,试试看 新人求救 struts2 超链接跳转错误 solr实现相关问题的搜索 在Spring中如何不让Session自动关闭 JSF 国际化资源绑定问题 Struts问题急 急用,请各位前辈,倾囊而诤 产生随机数 如何让鼠标在图片上停止时出现工具提示,急 js里alert()的问题 兄弟们,小弟刚接触JSP,帮忙解决一个问题。 晕~竟然发现JSP没颜色了嘎嘎~发帖求救! Java 中文乱码问题
try{
JdbcOdbc jdbc = new JdbcOdbc();
conn = jdbc.getConnection();
try{
stat=conn.createStatement();
sql = "select top 6 zs_id,dongtai_id,zs_biaoti from zs_dongtai order by zs_time desc";
res = stat.executeQuery(sql);
while (res.next()) {
%>
<tr>
<td width="20" height="19" align="center"><img src="images/top_point.gif" width="2" height="4" alt=""/></td>
<td><a href="c_congpanydongxin/<%=res.getString("zs_id").trim()%>/<%=res.getString("dongtai_id")%>.htm" title="<%=res.getString("zs_biaoti")%>" target="_blank"><%if (res.getString("zs_biaoti").length() >14) {%><%=res.getString("zs_biaoti").toString().substring(0, 14) %><%}else{%><%=res.getString("zs_biaoti") %><%} %></a></td>
</tr>
<%}}catch(Exception e){System.out.println(e.getMessage());}finally{try{res.close();stat.close();}catch(Exception e){}} %><%
try{
stat=conn.createStatement();
sql = "select top 12 zs_id,zs_company from zs_zhuce where zs_xianshi='是' order by zs_time desc";
res = stat.executeQuery(sql);
int j=0;
while (res.next()){
j=++j;%>
<tr>
<td width="10" height="19" align="center"><img src="images/ico2.gif" alt="" /></td>
<td width="155"><a href="comp_companyindex/<%=res.getString("zs_id").trim()%>.htm" title="<%=res.getString("zs_company")%>" target="_blank"><% if (res.getString("zs_company").length() > 12){%><%=res.getString("zs_company").toString().substring(0,12) %><%}else{%><%=res.getString("zs_company") %><%} %> </a></td>
</tr>
<%if(j==6){%>
</table></td>
<td width="5" valign="bottom"> </td>
<td width="155" valign="bottom"><table width="155" border="0" cellspacing="0" cellpadding="0">
<%}}}catch(Exception e){System.out.println(e.getMessage());}finally{try{res.close();stat.close();}catch(Exception e){}}%>
我就这样一直往下取数据,最后conn.close();
这样有问题吗?
Invalid state, the Connection object is closed.
这样的错误
首页不是有好多列表要取数据,对吧,取到某个列表时就断了,代码如上
public class JdbcOdbc {
private final String driver="net.sourceforge.jtds.jdbc.Driver";
private final String url="jdbc:jtds:sqlserver://localhost:1433/newcsdn";
private final String usename = "sasfsdf";
private final String password = "sfsdf";
private Connection conn = null;
public JdbcOdbc() {
try {
Class.forName(driver);
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
public Connection getConnection() {
try {
conn = DriverManager.getConnection(this.url, this.usename,
this.password);
} catch (Exception e) {
System.out.println(e.getMessage());
}
return conn;
}
}我写了这样一个类进行连接的,要用到的地方调用它