C\C++ 如何使用 JDBC 连接数据库???(windows 和 unix\linux 环境)100分求购!!! 看看core javaII最后一章 如何在c/c++中调用java不过这样做有意义吗 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 不是用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 declarationsinline 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);} 在 unix 用! 同志们! 在 unix ,linux 下,连接数据库的最好方法,可能就是jdbc 了,用c/c++能调用吗??? 省着为不同的数据库开发了,太难了,我们开发了oracle,sybase,mysql的了,不过要是有jdbc就好了,直接用 老外开发的,呵呵 这道面试题该怎么回答才完美 java applet中文乱码问题求教 java中access DBQ问题 求JDBC的连接实例。新人 截取字符串 JAVA新手的困惑 关于IO问题 在线等急呀 关于位移的问题,解惑马上给分!!! 如何限制iframe中脚本语言的执行 有谁能介绍有没有,java关于串口编程的书? Java中如何创建一个新文件新目录 菜鸟问题
#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);}