⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sightinfodao.java

📁 投票程序源代码,很好用的哦,我也是转载的!
💻 JAVA
字号:
/**
 * @SightInfoDao.java 2007-8-15 
 * @Author yangpeiliang
 * @E_mail:ypl728@hotmail.com
**/
package com.sigth;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.util.ArrayList;

public class SightInfoDao {
	
	private static SightInfoDao na = null ;
	private SightInfoDao ()
	{
	}

	public static SightInfoDao getInstance ()
	{
		if ( na == null )
	    {
	      na = new SightInfoDao () ;
	    }
	    return na ;
	}
	
	public static int getSightInfoPageNum ( int perPage )
	  {
	    int pageNum = 0 ;
	    CallableStatement oracleCs = null ;
	    Connection dbConn = null ;
	    try
	    {
	      dbConn = DBOracleConnPool.getInstance ().getConnection () ;
	      oracleCs = dbConn.prepareCall (
	          "{call PKG_SMS_SIGNT.getSightInfoNum(?,?)}" ) ;
	      oracleCs.setInt ( 1 , perPage ) ;
	      oracleCs.registerOutParameter ( 2 , oracle.jdbc.OracleTypes.INTEGER ) ;
	      oracleCs.execute () ;
	      pageNum = oracleCs.getInt ( 2 ) ;
	    }
	    catch ( Exception e )
	    {
	      e.printStackTrace () ;
	    }
	    finally
	    {
	      closeDB ( oracleCs , dbConn ) ;
	    }
	    return pageNum ;
	  }
	  
	/**
	   * 景点投票信息集合
	   * @return List
	   */
	  public static ArrayList getAllSightList (int currentPage , int perPage)
	  {
		ArrayList sightList = new ArrayList () ;
	    ResultSet rs = null ;
	    CallableStatement oracleCs = null ;
	    Connection dbConn = null ;
	    try
	    {
	      dbConn = DBOracleConnPool.getInstance ().getConnection () ;
	      oracleCs = dbConn.prepareCall (
	          "{? = call PKG_SMS_SIGNT.getSightInfoList(?,?)}" ) ;
	      oracleCs.registerOutParameter ( 1 , oracle.jdbc.OracleTypes.CURSOR ) ;
	      oracleCs.setInt ( 2 , currentPage ) ;
	      oracleCs.setInt ( 3 , perPage ) ;
	      oracleCs.execute () ;
	      rs = ( ResultSet ) oracleCs.getObject ( 1 ) ;
	      while ( rs.next () )
	      {
	    	  SightInfoBean sight = new SightInfoBean();
	    	  sight.setVoteNum(rs.getInt( "ballot_num" ));
	    	  sight.setSightName(rs.getString( "sight_name" ));
	    	  sight.setVoteTime(rs.getString( "updateTime" ));
	    	  sightList.add(sight);
	      }
	    }
	    catch ( Exception e )
	    {
	      e.printStackTrace () ;
	    }
	    finally
	    {
	      closeDB ( rs , oracleCs , dbConn ) ;
	    }
	    return sightList;
	  }
	  
	  /**
	   * 关闭数据库连接
	   * @param rs ResultSet 记录集
	   * @param os CallableStatement 存储过程集
	   * @param pool Connection 数据库连接类
	   */
	  public static void closeDB ( ResultSet rs , CallableStatement os ,
	                               Connection pool )
	  {
	    try
	    {
	      if ( rs != null )
	      {
	        rs.close () ;
	      }
	      if ( os != null )
	      {
	        os.close () ;
	      }
	      if ( pool != null )
	      {
	        pool.close () ;
	      }
	    }
	    catch ( Exception e )
	    {
	      rs = null ;
	      os = null ;
	      pool = null ;
	    }
	  }
	  
	  /**
	   * 关闭数据库连接
	   * @param os CallableStatement 存储过程集
	   * @param pool Connection 数据库连接类
	   */
	  private static void closeDB ( CallableStatement os , Connection pool )
	  {
	    try
	    {
	      if ( os != null )
	      {
	        os.close () ;
	      }
	      if ( pool != null )
	      {
	        pool.close () ;
	      }
	    }
	    catch ( Exception e )
	    {
	      os = null ;
	      pool = null ;
	    }
	  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -