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

📄 cachedpagebean.java

📁 java+oracle实现学生管理系统 学生信息的增删改查
💻 JAVA
字号:
package bean;

import java.sql.*;

public class CachedPageBean {
	static String serverName = "localhost";
	static String sDBDriver = "oracle.jdbc.driver.OracleDriver";
	static String dbInstance = "ora9i";
	static String sConnStr = "jdbc:oracle:thin:@"
+serverName+":1521:"+dbInstance;
	
	static String dbUser = "scott";
	static String userPwd = "tiger";
    
	/**
	*得到一个Connection对象
	*@return java.sql.Connection
	*/
    public static Connection getConnection()
    {
        Connection conn = null;
        try 
        {
			Class.forName(sDBDriver); 
conn = DriverManager.getConnection(sConnStr, 
dbUser, userPwd);             
		}		
		catch(ClassNotFoundException e) 
		{
			e.printStackTrace();
		}		
		catch(SQLException e1)
		{
		    e1.printStackTrace();
		}
		return conn;
    }
    /**
    *关闭指定的结果集
    *@param rs 要关闭的结果集
    */
    public static void closeResultSet(ResultSet rs)
    {
         if( rs != null)
    	 {
    	    try
    	    {
    	        rs.close();
    	    }
    	    catch(SQLException e)
    	    {            
    	    }
    	 }	    
    }
    /**
    *关闭指定的Statement
    *@param stmt 要关闭的Statement
    */
    public static void closeStatement(Statement stmt)
    {        
    	    if( stmt != null)
    	    {
    	        try
    	        {
    	            stmt.close();
    	        }
    	        catch(SQLException e)
    	        {    	        
    	        }
    	    }	
    }
    /**
    *关闭连接
    *@param conn 要关闭的连接
    */
    public static void closeConnection(Connection conn)
    {
	        if( conn != null)
    	    {
    	        try
    	        {
    	            conn.close();
    	        }
    	        catch(SQLException e)
    	        {
    	        }
    	    }
    }
	 /**
    获得总的记录数目
    */
    public static int getRowNumber()
    {
        Connection conn = getConnection();
        int num = 0;
        try
        {
            Statement stmt = conn.createStatement();
            String sql = "select count(*) as rowNumbers from addrestlist";
            ResultSet rs = stmt.executeQuery(sql);
            rs.next();
            num = rs.getInt("rowNumbers");
        }
        catch(SQLException e)
        {
            e.printStackTrace();
        }
        finally
        {
            closeConnection(conn);
        }
        return num;
    }
     /**
    根据指定的页面大小,获得页面数目
    */
    public static int getTotalPage(int pageSize)
    {
        int totalPage = 1;
        int tmpPage = 0;
        int rowNum = getRowNumber();
        tmpPage = rowNum % pageSize;
        if(tmpPage == 0)
        {
            totalPage = rowNum / pageSize;
        }else{
            totalPage = (int) (Math.floor(rowNum/pageSize)+1);
        }
        if (totalPage == 0)
        {
            totalPage = 1;
        }
        
        return totalPage;
    }
	public static ResultSet getAllResults() {
	    Connection conn = null;
	    Statement stmt = null;
	    ResultSet rs = null;
	    String sql = "select * from addrestlist order by id";
		try {
			conn = getConnection(); 
			//注意,返回的是可滚动的ResultSet
			stmt = conn.createStatement(
ResultSet.TYPE_SCROLL_INSENSITIVE,
                        ResultSet.CONCUR_READ_ONLY);
			rs = stmt.executeQuery(sql);
		} 
		catch(SQLException e) { 
			e.printStackTrace();
		}
		return rs;
	}
	
	
}

⌨️ 快捷键说明

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