看看core javaII最后一章 如何在c/c++中调用java不过这样做有意义吗

解决方案 »

  1.   

    不是用JDBC连的
    #include <ole2.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <fstream.h>
    #include <iostream.h>#import "c:\Program Files\Common Files\System\ADO\msado15.dll" \
        no_namespace rename("EOF", "EndOfFile")// Function declarations
    inline void TESTHR(HRESULT x) {if FAILED(x) _com_issue_error(x);};
    void ExecuteX(void);
    void ExecuteCommand(_CommandPtr pCmdTemp, _RecordsetPtr pRstTemp);
    void PrintOutput(_RecordsetPtr pRstTemp);
    void PrintProviderError(_ConnectionPtr pConnection);
    void PrintComError(_com_error &e);////////////////////////////////
    //      Main Function         //
    ////////////////////////////////void main()
    { if(FAILED(::CoInitialize(NULL)))
            return;

    ExecuteX();    ::CoUninitialize();}///////////////////////////////////
    //      ExecuteX Function        //
    ///////////////////////////////////void ExecuteX(void) 
    {
       HRESULT    hr = S_OK;    // Define string variables.
       _bstr_t strSQLDelete("delete Titles");   _bstr_t strCnn("Provider=sqloledb;Data Source=Baby;"
                "Initial Catalog=tempdb;User Id=sa;Password=;");    // Define ADO object pointers.
        // Initialize pointers on define.
        // These are in the ADODB::  namespace.
        _ConnectionPtr  pConnection = NULL;    try
        {
            // Open connection.
            TESTHR(pConnection.CreateInstance(__uuidof(Connection)));
            pConnection->Open (strCnn, "", "", adConnectUnspecified);        // Clear extraneous errors from the Errors collection.
            pConnection->Errors->Clear();        // Use the Connection object's Execute method to
            // execute SQL statement to restore data.
            //pConnection->Execute(strSQLDelete, NULL, adExecuteNoRecords); _bstr_t strSQLExeProc("exec xx");
            pConnection->Execute(strSQLExeProc, NULL, adExecuteNoRecords);        pConnection->Close();
        }    catch (_com_error &e)
        {
            PrintProviderError(pConnection);
            PrintComError(e);
        }
    }//////////////////////////////////////////
    //      ExecuteCommand Function         //
    //////////////////////////////////////////void ExecuteCommand(_CommandPtr pCmdTemp, _RecordsetPtr pRstTemp)
    {
        try
        {
            // CommandText property already set before function was called.
            pCmdTemp->Execute(NULL, NULL, adCmdText);        // Retrieve the current data by requerying the Recordset.
            pRstTemp->Requery(adCmdUnknown);
        }    catch(_com_error &e)
        {
            // Notify user of any errors that result from
            // executing the query.
            // Pass a connection pointer accessed from the Recordset.
            PrintProviderError(pRstTemp->GetActiveConnection());
            PrintComError(e);
        }
    }
    ///////////////////////////////////////////////
    //      PrintProviderError Function          //
    ///////////////////////////////////////////////void PrintProviderError(_ConnectionPtr pConnection)
    {
        // Print Provider Errors from Connection object.
        // pErr is a record object in the Connection's Error collection.
        ErrorPtr  pErr = NULL;    if( (pConnection->Errors->Count) > 0)
        {
            long nCount = pConnection->Errors->Count;
            // Collection ranges from 0 to nCount -1.
            for(long i = 0; i < nCount; i++)
            {
                pErr = pConnection->Errors->GetItem(i);
                printf("\t Error number: %x\t%s", pErr->Number,
                    pErr->Description);
            }
        }
    }//////////////////////////////////////
    //      PrintComError Function      //
    //////////////////////////////////////void PrintComError(_com_error &e)
    {
        _bstr_t bstrSource(e.Source());
        _bstr_t bstrDescription(e.Description());
        
        // Print Com errors.
        printf("Error\n");
        printf("\tCode = %08lx\n", e.Error());
        printf("\tCode meaning = %s\n", e.ErrorMessage());
        printf("\tSource = %s\n", (LPCSTR) bstrSource);
        printf("\tDescription = %s\n", (LPCSTR) bstrDescription);}
      

  2.   

    在 unix 用! 同志们!
      

  3.   

    在 unix ,linux 下,连接数据库的最好方法,可能就是jdbc 了,用c/c++能调用吗???
      

  4.   

    省着为不同的数据库开发了,太难了,我们开发了oracle,sybase,mysql的了,不过要是有jdbc就好了,直接用 老外开发的,呵呵