- 论坛徽章:
- 0
|
<%
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance(); //载入驱动程序类别
Connection conn = DriverManager.getConnection("jdbc:microsoft:sqlserver://IP:1433;DatabaseName=test","jing","shujuku");; //建立数据库链接
//建立Statement对象
Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
%>这是连接数据库的文件,下面要两次用到rs,我第一次用完了之后怎么释放呢?
然后再怎么重新定义呢?
<%String sql1="Select * from product where pro_name='news' and img is not null";
ResultSet rs1 = stmt.executeQuery(sql1);
while (rs1.next()){
String id=rs1.getString("id");
String img=rs1.getString("img");
String title=rs1.getString("title");
%>
<table width="100%" border="0" cellpadding="0" cellspacing="3">
<tr>
<td><img src="admin/img/<%=img%>" width="158" height="126"></td>
</tr>
<tr>
<td height="41" class="text03"><a href="news_more.jsp?id=<%=id%>"class="2"><%=title%></a></td>
</tr>
</table>
<%}
rs1.close();
%>
</div></td>
</tr>
</table></td>
</tr>
</table></td>
<td width="410" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="4">
<tr>
<td><table width="100%" border="0" cellspacing="8" cellpadding="0">
<%String sql2="Select * from product where pro_name='news' order by id desc";
int i;
ResultSet rs2 = stmt.executeQuery(sql2);
i=0;
while((i<7) && (rs2.next())){
String id=rs2.getString("id");
String title=rs2.getString("title");
String time=rs2.getString("pub_date");
time=time.substring(0,10);
%>
<tr>
<td width="5%"><div align="center"><img src="image/20.jpg" width="6" height="9"></div></td>
<td width="70%"><a href="news_more.jsp?id=<%=id%>" class="2"><%=title%></a></td>
<td width="25%" style="font-size=12px">[<%=time%>]</td>
</tr>
<%i=i+1;
}
rs2.close();
%>
上面是我用到两次rs。第二次,我想重新定义,请问怎么用,我是截取的一段代码,不太规范,大家请谅。 |
|