小而精的流言系统

源代码在线查看: readguestbook.java

软件大小: 1284 K
上传用户: hufei108
关键词:
下载地址: 免注册下载 普通下载 VIP

相关代码

				package guestbook;
				
				import java.sql.*;
				import javax.sql.DataSource;
				
				public class ReadGuestbook{
				  private int id;
				  private String username =null;
				  private String userqq=null;
				  private String useremail=null;
				  private String content = null;
				  private String reply =null;
				  private String writetime = null;
				  private String replytime = null;
				  private boolean flag;
				  private int rowCount;
				  private Statement stmt=null;
				  private Connection conn=null;
				  private ResultSet rs=null;
				  private DataSource dataSource=null;
				  //构造函数初始化ResultSet
				  public ReadGuestbook(String path){
				    Init init=new Init(path);
				    dataSource=LinkDB.getDB();
				    if (dataSource==null) {
				      LinkDB.setDB(init.getDriverName(),init.getDBURL(),init.getDBUser(),init.getDBPassword());
				      dataSource=LinkDB.getDB();
				    }
				    try{
				        conn = dataSource.getConnection();
				        stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
				        rs = stmt.executeQuery("select * from guestbook");
				        flag = rs.last();
				        rowCount=rs.getRow();
				    }
				    catch(SQLException e){
				      throw new RuntimeException(e);
				    }
				  }
				  //读取pointPosition设置的指针下的数据
				  public void readSQL(int pointPosition){
				    try{
				      if(flag&&rs.absolute(pointPosition)){
				        id=rs.getInt("id");
				        username = rs.getString("name").trim();
				        userqq = rs.getString("qq").trim();
				        useremail = rs.getString("email").trim();
				        reply = rs.getString("reply").trim();
				        replytime = rs.getString("replytime").trim();
				        content = rs.getString("note").trim();
				        writetime = rs.getString("writetime").trim();
				        flag = rs.next();//判断记录集是否结束
				        if(!flag) close();//记录集结束就关闭连接
				      }
				    }
				    catch(SQLException e){
				      throw new RuntimeException(e);
				    }
				  }
				  public int getID(){
				    return id;
				  }
				  public String getUsername(){
				    if(username==null) return "";
				    else return username;
				  }
				  public String getUserqq(){
				    if(userqq==null) return "";
				    else return userqq;
				  }
				  public String getUseremail(){
				    if(useremail==null) return "";
				    else return useremail;
				  }
				  public String getContent(){
				    if(content==null) return "";
				    else return content;
				  }
				  public String getReply(){
				    if(reply==null) return "";
				    else return reply;
				  }
				  public String getWritetime(){
				    if(writetime==null) return "";
				    else return writetime;
				  }
				  public String getReplytime(){
				    if(replytime==null) return "";
				    else return replytime;
				  }
				  public boolean isEnd(){
				    return flag;
				  }
				  public int getRowcount(){
				    return rowCount;
				  }
				  public void close(){
				    try {
				      rs.close();
				      stmt.close();
				      conn.close();
				      LinkDB.shutdownDataSource(dataSource);
				    }
				    catch (SQLException e) {
				      throw new RuntimeException(e);
				    }
				  }
				}			

相关资源