日期:2014-05-17 浏览次数:20838 次
/*
* 网站JAVABEAN
* 所有帖子分类列表.
* 使用数据源连接.
* 前后台共用JAVABEAN.
*/
package mybean;
import java.sql.*;
import mybean.DBConnSource;
public class StyleList {
private String tableName;
private Statement stmt;
private ResultSet rs;
private DBConnSource dbc;
public StyleList(){}
public void setTableName(String n){
this.tableName=n;
}
public StringBuffer getBuffer(){
StringBuffer buffer=new StringBuffer();
dbc=new DBConnSource("jdbc/myweb");
try{
stmt=dbc.getStmt();
}catch(Exception e){
System.out.print("不能连接到数据源"+e.toString());
}
try{ //这就是36行;
String strSql="SELECT * FROM "+tableName;
rs = stmt.executeQuery(strSql);
while(rs.next()){
buffer.append("<a href='style.jsp?style="+rs.getString("style")+"' target=_blank>"+rs.getString("style")+"</a>");
buffer.append(" ");
}
}catch(SQLException e){
System.out.print("结果集rs获取出错"+e.toString());
}finally{
try{ //关闭 ResultSet rs.
if(rs!=null){
rs.close();
}
}catch(SQLException ex){
System.out.print("关闭rs出错"+ex.toString());
}finally{
try{ // 关闭 Statement stmt.
if(stmt!=null){