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

📄 adoutils.java

📁 vc ADO 连接数据库
💻 JAVA
字号:
// ADOUTILS:  Utility functions for demonstrating ADO in Java
//

import com.ms.com.*;
import java.awt.*;

import LogEx;

class ADOUtils
{
    public LogEx Log1;

    public void init()
    {
        Log1 = new LogEx();
        Log1.init();
    }

    public void destroy()
    {
        if( Log1 != null ) Log1 = null;
    }

//--------------------------
// Error/Exception Handlers 
//--------------------------

    public long AdoErrorEx( List List1, msado15._Connection Conn1, LogEx Log1 )
    {
        // Local Error Objects
        msado15.Errors      Errs1 = null;
        msado15.Error       Err1  = null;

        long        nCount;
        Variant     v = new Variant();

        // Try/Catch Block
        try
        {
            // For any error conDition, show results to user
            Log1.Log( "*** ADO ERROR CONDITION ***" );

            // Enumerate Errors Collection and Display properties of each object.
            Errs1  = Conn1.getErrors();
            nCount = Errs1.getCount();

            // Loop through Errors Collection
            for( long i = 0; i < nCount; i++ )
            {
                v.putInt( (int) i );
            
                // Get Error Item
                Err1 = Errs1.getItem( v );

                // Get Error Number
                Log1.Log( "    Number " + Err1.getNumber() );

                // Get Error Description
                Log1.Log( "        Description = " + Err1.getDescription()  );

                // Get Error Source
                Log1.Log( "        Source      = " + Err1.getSource() );

                // Get Help File
                Log1.Log( "        HelpFile    = " + Err1.getHelpFile() );

                // Get Help File Context
                Log1.Log( "        HelpContext = " + Err1.getHelpContext() );

                // Get Native Error
                Log1.Log( "        NativeError = " + Err1.getNativeError() );

                // Get SQL State
                Log1.Log( "        SQLState    = " + Err1.getSQLState() );

                // Release Error Object
                if ( Err1 != null ) Err1 = null;
            }
        }
        // Catch Blocks
        catch (com.ms.com.ComFailException e)    
        {
            Log1.Log( "*** UNABLE TO LOG ADO ERROR *** (class ComFailException was raised while logging exception)" );
            Log1.LogReset();
            Log1.LogException( e );
            Log1.LogDisplay( List1 );
        }
        catch(Exception e) 
        {
            Log1.Log( "*** UNABLE TO LOG ADO ERROR *** (class Exception was raised while logging exception)" );
            Log1.LogReset();
            Log1.LogException( e );
            Log1.LogDisplay( List1 );
        }

        // Clean-up
        if ( Errs1 != null ) Errs1 = null;
        if ( Err1  != null ) Err1  = null;

        return 0;
    }

//-------------------
// Utility Functions
//-------------------

    public void DumpProperty( List List1, msado15._Connection Conn1, msado15.Properties Props1 )
    {
        long                    nCount;
        String                  s = new String();
        Variant                 v = new Variant();

        // Try/Catch Block
        try
        {
            // Display # of properties found
            nCount = Props1.getCount();
            List1.addItem( "    " + nCount + " Properties Found" );

            // Enumerate through properties collection
            for ( int i = 0; i < nCount; i++ )
            {
                v.putInt( (int) i );

                // Display Name
                List1.addItem( "    Property " + (i+1) + "  " + Props1.getItem( v ).getName() );

                // Display Type
                List1.addItem( "        ...Type       = " + GetType( Props1.getItem( v ).getType() ) );

                // Display Value
                List1.addItem( "        ...Value      = " + Props1.getItem( v ).getValue() );

                // Display Attributes
                List1.addItem( "        ...Attributes = " + GetPropertyAttributes( Props1.getItem( v ).getAttributes() ) );
            }
        }
        // Catch Blocks
        catch (com.ms.com.ComFailException e)    
        {
            Log1.LogReset();
            Log1.LogException( e );
            AdoErrorEx( List1, Conn1, Log1 );
            Log1.LogDisplay( List1 );
        }
        catch(Exception e) 
        {
            Log1.LogReset();
            Log1.LogException( e );
            AdoErrorEx( List1, Conn1, Log1 );
            Log1.LogDisplay( List1 );
        }
    }

    String GetPropertyAttributes( int e )
    {
       String strTmp = new String("");
       int    P1     = e & msado15.PropertyAttributesEnum.adPropNotSupported;
       int    P2     = e & msado15.PropertyAttributesEnum.adPropRequired;
       int    P3     = e & msado15.PropertyAttributesEnum.adPropOptional;
       int    P4     = e & msado15.PropertyAttributesEnum.adPropRead;
       int    P5     = e & msado15.PropertyAttributesEnum.adPropWrite;
   
       if ( P1 != 0 )  strTmp += "NotSupported ";
       if ( P2 != 0 )  strTmp += "Required ";
       if ( P3 != 0 )  strTmp += "Optional ";
       if ( P4 != 0 )  strTmp += "Read ";
       if ( P5 != 0 )  strTmp += "Write ";
 
       return strTmp;
    }


    String GetType( int e )
    {
        String sType;

        switch (e)
        {   case msado15.DataTypeEnum.adSmallInt:         sType = "Short Int"; break;
            case msado15.DataTypeEnum.adInteger:          sType = "Long Int"; break;
            case msado15.DataTypeEnum.adSingle:           sType = "Single Float"; break;
            case msado15.DataTypeEnum.adDouble:           sType = "Double Float"; break;
            case msado15.DataTypeEnum.adCurrency:         sType = "Currency"; break;
            case msado15.DataTypeEnum.adDate:             sType = "Date/Time"; break;
            case msado15.DataTypeEnum.adBSTR:             sType = "System String"; break;
            case msado15.DataTypeEnum.adIDispatch:        sType = "Object, IDispatch"; break;
            case msado15.DataTypeEnum.adBoolean:          sType = "Boolean"; break;
            case msado15.DataTypeEnum.adVariant:          sType = "Variant"; break;
            case msado15.DataTypeEnum.adDecimal:          sType = "Decimal"; break;
            case msado15.DataTypeEnum.adTinyInt:          sType = "Signed Tiny Int"; break;
            case msado15.DataTypeEnum.adUnsignedTinyInt:  sType = "Unsigned Tiny Int"; break;
            case msado15.DataTypeEnum.adUnsignedSmallInt: sType = "Unsigned Short Int"; break;
            case msado15.DataTypeEnum.adUnsignedInt:      sType = "Unsigned Long Int"; break;
            case msado15.DataTypeEnum.adBigInt:           sType = "Signed Large Int"; break;
            case msado15.DataTypeEnum.adUnsignedBigInt:   sType = "Unsigned Large Int"; break;
            case msado15.DataTypeEnum.adGUID:             sType = "GUID"; break;
            case msado15.DataTypeEnum.adBinary:           sType = "Bytes"; break;
            case msado15.DataTypeEnum.adChar:             sType = "Char"; break;
            case msado15.DataTypeEnum.adWChar:            sType = "Unicode String"; break;
            case msado15.DataTypeEnum.adNumeric:          sType = "Numeric"; break;
            case msado15.DataTypeEnum.adUserDefined:      sType = "User Defined"; break;
            case msado15.DataTypeEnum.adDBDate:           sType = "DB Date"; break;
            case msado15.DataTypeEnum.adDBTime:           sType = "DB Time"; break;
            case msado15.DataTypeEnum.adDBTimeStamp:      sType = "DB Date/Time"; break;
            case msado15.DataTypeEnum.adVarChar:          sType = "VarChar"; break;
            case msado15.DataTypeEnum.adLongVarChar:      sType = "LongVarChar"; break;
            case msado15.DataTypeEnum.adVarBinary:        sType = "VarBinary"; break;
            case msado15.DataTypeEnum.adLongVarBinary:    sType = "LongVarBinary"; break;
            default:                                      sType = "Unknown"; break;
        }
        return sType;
    }

    public void LogException( Exception e, List List1, msado15._Connection Conn1 )
    {
        Log1.LogReset();
        Log1.LogException( e );
        AdoErrorEx( List1, Conn1, Log1 );
        Log1.LogDisplay( List1 );
    }

    public void LogException( com.ms.com.ComFailException e, List List1, msado15._Connection Conn1 )
    {
        Log1.LogReset();
        Log1.LogException( e );
        AdoErrorEx( List1, Conn1, Log1 );
        Log1.LogDisplay( List1 );
    }
}

⌨️ 快捷键说明

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