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

📄 dboperater.java

📁 JAVA邮件系统
💻 JAVA
字号:
/* 
 *
 */

import java.sql.*;

/**
 * 
 *
 * @author Lizhaoshan
 */

public class DBOperater
{
	Connection m_hDB;
	Statement  m_hStmt;
	ResultSet  m_hRecordSet;
	
	static  int   m_nConn=0;
	static  int   m_nRset=0;
	DBOperater( String system )
	{
		try{
			m_hDB = CommonMethods.getDBConnection (system);
		}catch(Exception e){
		}
	
		m_hStmt = null;
		m_hRecordSet = null;
		m_nConn++;
	}


	public boolean CanUse(){
		return m_hDB!=null;
	}
	
	
	public void close(){
		try{
			if( m_hRecordSet!=null ){
				m_hRecordSet.close ();
				m_hRecordSet = null;
				m_nRset--;
				//System.out.println( "rset:" +m_nRset); 
			}
		}catch(Exception e){
		}
		try{
			if( m_hStmt!=null ){
				m_hStmt.close ();
				m_hStmt = null;
			}
		}catch(Exception e){
		}
		try{
			if( m_hDB!=null ){
				if(!m_hDB.isClosed ())				
					m_hDB.close ();
				m_hDB = null;
				m_nConn--;

			}
		}
		catch(Exception e){
		}
	}
	
	protected void finalize(){
		close();
	}
	
	
	boolean closeForRS(){
		try{
			m_hRecordSet.close ();
			m_hRecordSet=null;
			m_nRset--;
			//System.out.println( "rset:" +m_nRset); 
		}
		catch(Exception e){
			return false;
		}
		
		return true;
	}
	
	
	public int executeUpdate(String sql1){
		byte[] byte1 =null;
		String sql =null;
		
		if( CanUse()==false ){
			System.out.println ("can't use");
			return 0;
		}

		if( m_hRecordSet!=null )
			closeForRS();
		
		if(m_hStmt==null){
			try{
				m_hStmt = m_hDB.createStatement ();
			}catch(Exception e){
				System.out.println ("sql error:"+sql+e.toString() );
				return 0;
			}
		}
			
		int nTag=0;
		try{
			byte1 = sql1.getBytes ("8859_1"); 
			sql = new String(byte1,"GB2312");
			nTag = m_hStmt.executeUpdate (sql);
		}catch(Exception e){
			System.out.println ("error in:"+sql);
			System.out.println ("error in:"+e.toString() );
			return 0;
		}
		

		return nTag;
	}
	
	public ResultSet executeQuery( String sql1 ){
		byte[] byte1 =null;
		String sql =null;
		if( CanUse()==false ){
			System.out.println ("can't use");
			return null;
		}

		if( m_hRecordSet!=null )
			closeForRS();
		
		if(m_hStmt==null){
			try{
				m_hStmt = m_hDB.createStatement ();
			}catch(Exception e){
				System.out.println ("can't use");
				return null;
			}
		}

		try{
			m_hStmt.setMaxFieldSize (0);
			byte1 = sql1.getBytes ("8859_1"); 
			sql = new String(byte1,"GB2312");
			m_hRecordSet = m_hStmt.executeQuery (sql);
			m_nRset++;
			//System.out.println( "rset:" +m_nRset); 
		}catch(Exception e){
				System.out.println ("sql error:"+sql);
				System.out.println ("sql error:"+e.toString() );
			return null;
		}

		return m_hRecordSet;
	}
}

⌨️ 快捷键说明

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