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

📄 report.java

📁 WAP PUSH后台源码,WAP PUSH后台源码
💻 JAVA
字号:
package com.sxit.wap.report;

import java.sql.*;
import java.util.*;
import com.sxit.wap.common.*;
import com.sxit.wap.exception.*;

public abstract class Report {
	public Report () {
	}
	public String[] getReportHeader () {
		return null;
	}
	public String getReportTitle () {
		return "";
	}

	public java.util.Date getNextTime(java.util.Date date){
		java.util.Calendar calendar = java.util.Calendar.getInstance();
		calendar.setTime(date);
		calendar.add(java.util.Calendar.MINUTE,24*60);
		return calendar.getTime();
	}

	public Collection queryBySql ( String sql, int beginRow, int endRow ) throws SysException {
		Connection dbConnection = null;
		Statement stmt = null;
		ResultSet rs = null;
		ArrayList list = new ArrayList ();
		try {
			dbConnection = getDBConnection ();
			stmt = dbConnection.createStatement ();
			rs = stmt.executeQuery ( sql );
			ResultSetMetaData rsmd = rs.getMetaData ();
			int row = 0;
			while ( rs.next () ) {
				if ( ++row < beginRow )
					continue;
				if ( row > endRow )
					break;
				Hashtable element = new Hashtable ();
				for ( int i = 1; i <= rsmd.getColumnCount (); i++ ) {
					String columnName = rsmd.getColumnName ( i );
					String fieldName = Function.format ( columnName );
					String fieldType = ColumnType.getFieldType ( Database.dbType, rsmd, i );
					if ( fieldType == null )
						continue;
					if ( "Timestamp".equals ( fieldType ) ) {
						element.put ( fieldName, rs.getTimestamp ( columnName ) );
					} else if ( "String".equals ( fieldType ) ) {
						String value = Function.readDBEncode ( rs.getString ( columnName ) );
						if ( value == null )
							value = "";
						element.put ( fieldName, value );
					} else if ( "int".equals ( fieldType ) ) {
						element.put ( fieldName, String.valueOf ( rs.getInt ( columnName ) ) );
					} else if ( "long".equals ( fieldType ) ) {
						element.put ( fieldName, String.valueOf ( rs.getLong ( columnName ) ) );
					} else if ( "float".equals ( fieldType ) ) {
						element.put ( fieldName, String.valueOf ( rs.getFloat ( columnName ) ) );
					}
				}
				list.add ( element );
			}
			return list;
		} catch ( SQLException e ) {
			Debug.println ( sql + "\n" + "SQLException while execute queryBySql mothod :\n" + e );
			throw new SysException ( "SQLException while execute queryBySql mothod :\n" + e );
		} finally {
			closeResultSet ( rs );
			closeStatement ( stmt );
			closeConnection ( dbConnection );
		}
	}

	public int getRowCountBySql ( String sql ) throws SysException {
		Connection dbConnection = null;
		Statement stmt = null;
		ResultSet rs = null;
		int rowCount = 0;
		try {
			dbConnection = getDBConnection ();
			stmt = dbConnection.createStatement ();
			rs = stmt.executeQuery ( sql );
			if ( rs.next () ) {
				rowCount = rs.getInt ( 1 );
			} else {
				Debug.println ( sql + "\n" + "ERROR in get row count!!" );
				//throw new SysException ( "ERROR in get row count!!" );
			}
			return rowCount;
		} catch ( SQLException e ) {
			Debug.println ( sql + "\n" + "SQLException while execute getRowCountBySql mothod :\n" + e );
			throw new SysException ( "SQLException while execute getRowCountBySql mothod :\n" + e );
		} finally {
			closeResultSet ( rs );
			closeStatement ( stmt );
			closeConnection ( dbConnection );
		}
	}

	private Connection getDBConnection () throws SysException {
		return Database.getConnection ();
	}

	private void closeConnection ( Connection dbConnection ) throws SysException {
		try {
			if ( dbConnection != null && !dbConnection.isClosed () ) {
				dbConnection.close ();
				dbConnection = null;
			}
		} catch ( SQLException se ) {
		//throw new SysException("SQL Exception while closing DB connection : \n" + se);
		}
	}

	private void closeResultSet ( ResultSet result ) throws SysException {
		try {
			if ( result != null ) {
				result.close ();
			}
		} catch ( SQLException se ) {
		//throw new SysException("SQL Exception while closing Result Set : \n" + se);
		}
	}

	private static void closeStatement ( Statement stmt ) throws SysException {
		try {
			if ( stmt != null ) {
				stmt.close ();
			}
		} catch ( SQLException se ) {
		//throw new SysException("SQL Exception while closing Statement : \n" + se);
		}
	}
}

⌨️ 快捷键说明

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