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

📄 listings.java

📁 vc ADO 连接数据库
💻 JAVA
字号:
//******************************************************************************
// Listings.java:	Applet
//
//******************************************************************************
import java.applet.*;
import java.awt.*;
import com.ms.com.*;

//==============================================================================
// Main Class for applet Listings
//
//==============================================================================
public class Listings extends Applet
{

	// TODO: Place additional applet code here

    //-------------------------------------------------------------------
    // CODE Listing:  Opening an ADO Recordset in Java
    //-------------------------------------------------------------------

    public static void OpeningADORecordset()
    {
        msado15._Recordset  Rs1        = new msado15.Recordset();
        Variant Connect    = new Variant( "DSN=AdoDemo;UID=admin;PWD=;" );
        Variant Source     = new Variant( "SELECT * FROM Authors" );
        int     LockType   = msado15.CursorTypeEnum.adOpenForwardOnly;
        int     CursorType = msado15.LockTypeEnum.adLockReadOnly;
        int     Options    = -1;

        Rs1.Open( Source, Connect, LockType,  CursorType, Options );
        Rs1.Close();
        Rs1 = null;
    }

    //-------------------------------------------------------------------
    // CODE Listing:  ADO Error Handling in Java
    //-------------------------------------------------------------------

    public static void ErrorHandlingWithJava()
    {
        msado15._Connection Conn1      = new msado15.Connection();

        try
        {
            Conn1.Open( "", "", "", -1  );
        }
        // Catch Blocks -- These catch blocks are a subset of the 
        //                 Exception Handling demonstrated in LogEx.Java &
        //                 AdoUtils.java in the Java Rosetta Stone Samples    
        catch (com.ms.com.ComFailException e)    
        {
            // Test if Connection.Errors Collection is non-empty 
            AdoErrorEx( Conn1 );

            // Crack open ComFailure class that wraps COM Exceptions
            System.out.println( "ComFailException Class Raised:" );
            System.out.println( "Exception Class = " + e.getClass()   );
            System.out.println( "Error Message   = " + e.getMessage() );
            System.out.println( "Failed HRESULT  = " + e.getHResult() ); 
        }
        catch(Exception e) 
        {
            // Test if Connection.Errors Collection is non-empty
            AdoErrorEx( Conn1 );

            // Crack open Java Exception class
            System.out.println( "Exception Class Raised:" );
            System.out.println( "Exception Class = " + e.getClass()   );
            System.out.println( "Error Message   = " + e.getMessage() );
        }
    }

    public static void AdoErrorEx( msado15._Connection Conn1 )
    {
        // Local Error Objects
        msado15.Errors      Errs1 = null;
        msado15.Error       Err1  = null;

        long        nCount;
        Variant     v = new Variant();

        if ( Conn1 == null )
            return;

        Errs1  = Conn1.getErrors();
        nCount = Errs1.getCount();
        for( long i = 0; i < nCount; i++ )
        {
            v.putInt( (int) i );
            Err1 = Errs1.getItem( v );
            System.out.println( "    Number " + Err1.getNumber() );
            System.out.println( "        Description = " + Err1.getDescription()  );
            if ( Err1 != null ) Err1 = null;
        }
        if ( Errs1 != null ) Errs1 = null;
    }

    public static void main( String args[])
    {
        System.out.println("Starting...\n");

        OpeningADORecordset();
        ErrorHandlingWithJava();

        System.out.println( "Done!\n" );
    }

}

⌨️ 快捷键说明

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