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

📄 common.java

📁 一套完整的工商12315的源程序jsp部分在12315里,后台JAVA部分在gs12315src里,没有打包数据库.
💻 JAVA
字号:
/**
 * Common.java       07/01/2002,
 * Author:
 *
 * Copyright (c)  2002 Censoft Corp.
 * Beijing China
 * All rights reserved.
 *
 * Modifier:
 * Time:
 ***/
package com.gs.util;

import javax.naming.*;
import java.util.*;
import java.sql.*;
import javax.sql.*;
import com.gs.db.dbimp.*;

public class Common{
    /**
     * 获得数据库连接
     * @return Returns java.sql.Connection
     */
    public static Connection getConnection() throws AppException {

      return DbConnectionManager.getConnection();
      /*
          Connection conn = null;
               try{
          Context ctx = new InitialContext();
          DataSource ds = (DataSource) ctx.lookup(JNDINames.JDBC_ORACLE_IN);
          conn = ds.getConnection();
          Debug.print("Common.getConnnection:" + conn);
          return conn;
               } catch(SQLException sqle){
          throw new AppException("连接数据库失败!错误信息: " + sqle.getMessage());
               } catch(Exception e){
          throw new AppException("连接数据库失败!错误信息: " + e.getMessage());
               }
       */
    }

    /**
     * get j2ee server context
     * @return Returns javax.naming.Context
     */
    public static Context getContext() throws AppException{
        Context ctx = null;
        try{
            Hashtable env = new Hashtable();
            env.put(Context.INITIAL_CONTEXT_FACTORY,"com.ibm.websphere.naming.WsnInitialContextFactory");
            //env.put(Context.PROVIDER_URL, providerURL);
            ctx = new InitialContext(env);
            return ctx;
        } catch(NamingException ne){
            throw new AppException("common.getContext: NamingException while getting context " + ne.getMessage());
        } catch(Exception e){
            throw new AppException("common.getContext: Exception while getting context " + e.getMessage());
        }
    }

    /**
     * <P>Description:</p>
     * @param
     * @return none
     */
    public static void clearUp(ResultSet rs,Statement stmt,Connection conn) throws AppException{
        try{
            if(rs != null){
                rs.close();
            }
        } catch(SQLException sqle){
            Debug.println("[Common]cleanup======SQLException=" + sqle);
            throw new AppException((Exception) sqle);
        }

        try{
            if(stmt != null){
                stmt.close();
            }
        } catch(SQLException sqle){
            Debug.println("[Common]cleanup=============SQLException=" + sqle);
            throw new AppException((Exception) sqle);
        }

        try{
            if(conn != null && !conn.isClosed()){
                conn.close();
            }
            Debug.print("conn已关闭:" + conn);
        } catch(SQLException sqle){
            Debug.println("[Common]cleanup=============SQLException=" + sqle);
            throw new AppException((Exception) sqle);
        }
    }

    /**
     * 分页查询方法
     * @param Connection conn 数据库连接
     * @param String sql 待查询的sql
     * @param int page 页码
     * @param int cpp 页容量
     * @return ArrayList
     */
    public static ResultSet getPageRS(Connection conn,String sql,int page,int cpp) throws AppException{
        Statement stmt = null;
        ResultSet rs = null;
        try{
            stmt = conn.createStatement();
            StringBuffer sqlBuf = new StringBuffer();
            sqlBuf.append("select * from ((select t.*,ROWNUM as rsNumRow from ( ");
            sqlBuf.append(sql);
            sqlBuf.append(" ) t ) ) where rsNumRow>");
            sqlBuf.append(cpp * (page - 1));
            sqlBuf.append(" and rsNumRow<=");
            sqlBuf.append(cpp * page);
            Debug.println("[Common--->getPageRS]分页查询方法-->" + sqlBuf.toString());
            rs = stmt.executeQuery(sqlBuf.toString());
        } catch(Exception e){
            Debug.println("[Common--->getPageRS]Exception is : " + e.getMessage());
            throw new AppException(e.getMessage());
        }
        return rs;
    }
}

⌨️ 快捷键说明

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