[問題] VS2005 + MYSQL Connector

看板C_and_CPP (C/C++)作者 (重新來過)時間15年前 (2010/08/04 01:43), 編輯推噓2(2013)
留言15則, 2人參與, 最新討論串1/1
( *[1m *[m 為色碼,可以按 Ctrl+V 預覽會顯示的顏色 ) ( 未必需要依照此格式,文章條理清楚即可 ) 遇到的問題: (題意請描述清楚) 欲連到localhost的MYSQL伺服器, 經過一番努力總算是將complier完成 但是在debug mode下會出現錯誤訊息而卡住 不知道問題出在何方 希望得到的正確結果: 能正確連線至伺服器上作query 程式跑出來的錯誤結果: 於 0x71bfb9f0 的 MYSQL Linking.exe 中發生未處理的例外狀況: 0xC0000005: 讀取位 置 0xcccccccc 時發生存取違規 開發平台: (例: VC++ or gcc/g++ or Dev-C++, Windows or Linux) windosws vista Visual studio 2005 C++ & mysql-connector-c++-1.0.5 有問題的code: (請善用置底文標色功能) /* Standard C++ includes */ #include <stdlib.h> #include <iostream> /* Include directly the different headers from cppconn/ and mysql_driver.h + mysql_util.h (and mysql_connection.h). This will reduce your build time! */ #include <mysql_driver.h> #include <mysql_connection.h> #include <cppconn/driver.h> #include <cppconn/exception.h> #include <cppconn/resultset.h> #include <cppconn/statement.h> using namespace std; using namespace sql; Driver *driver; Connection *con; int main(void) { cout << endl; cout << "Running 'SELECT 'Hello World!' AS _message'..." << endl; try { sql::Statement *stmt; sql::ResultSet *res; /* Create a connection */ driver = get_driver_instance(); con = driver->connect("tcp://127.0.0.1:8080", "localhost", "xxxx"); /* Connect to the MySQL test database */ con->setSchema("test"); stmt = con->createStatement(); res = stmt->executeQuery("SELECT 'Hello World!' AS _message"); while (res->next()) { cout << "\t... MySQL replies: "; /* Access column data by alias or column name */ cout << res->getString("_message") << endl; cout << "\t... MySQL says it again: "; /* Access column fata by numeric offset, 1 is the first column */ cout << res->getString(1) << endl; } delete res; delete stmt; delete con; } catch (sql::SQLException &e) { cout << "# ERR: SQLException in " << __FILE__; cout << "(" << __FUNCTION__ << ") on line " << __LINE__ << endl; cout << "# ERR: " << e.what(); cout << " (MySQL error code: " << e.getErrorCode(); cout << ", SQLState: " << e.getSQLState() << " )" << endl; } cout << endl; return EXIT_SUCCESS; } 補充說明: 在 con = driver->connect()這裡即出現問題 狀況類同16171 include folder & linking library有照 http://blog.ulf-wendel.de/?p=215 的說明 希望有經驗的前輩能給建議 謝謝~ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 218.35.17.150

08/04 09:16, , 1F
存取0xCCCCCCCC的錯誤, 多半是發生在你有某些local var,
08/04 09:16, 1F

08/04 09:17, , 2F
沒有經過合適的初始化就對它做存取, 常見的可能就是一個
08/04 09:17, 2F

08/04 09:17, , 3F
指標變數, 沒有指到合法位址, 沒有new/malloc, 沒給其他
08/04 09:17, 3F

08/04 09:18, , 4F
初值就拿來用了, 看你的錯誤訊息應該是拿來讀....@_@"
08/04 09:18, 4F

08/04 09:19, , 5F
PS. 第一行指的是在VC debug build的情況....
08/04 09:19, 5F

08/04 11:50, , 6F
先謝謝你的回文 我有想過你所提到的問題 但它初始化
08/04 11:50, 6F

08/04 11:52, , 7F
我不清楚該怎麼下才適當 而在其他範例沒找到參考 故沒做
08/04 11:52, 7F

08/04 11:53, , 8F
可以再多給一些指導嗎? 謝謝~
08/04 11:53, 8F

08/04 12:21, , 9F
先check 這行 driver = get_driver_instance();
08/04 12:21, 9F

08/04 12:22, , 10F
driver拿回來的結果, 如果有正確get回來就不該是
08/04 12:22, 10F

08/04 12:22, , 11F
0xCCCCCCCC吧?_? 那無論是這行還是connect那行,
08/04 12:22, 11F

08/04 12:23, , 12F
查一下有沒有檢查error的function或機制....
08/04 12:23, 12F

08/04 12:23, , 13F
(指類似 GetLastError() 這種東西的@_@")
08/04 12:23, 13F

08/05 00:00, , 14F
換走sql::mysql::MySQL_Driver *driver 有拿到值
08/05 00:00, 14F

08/05 00:01, , 15F
不過 con這一行依舊抓不到connect內的東西....Orz
08/05 00:01, 15F
文章代碼(AID): #1CM5Kgkq (C_and_CPP)
文章代碼(AID): #1CM5Kgkq (C_and_CPP)