[問題] VS2005 + MYSQL Connector
( *[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
08/04 09:16, 1F
→
08/04 09:17, , 2F
08/04 09:17, 2F
→
08/04 09:17, , 3F
08/04 09:17, 3F
→
08/04 09:18, , 4F
08/04 09:18, 4F
→
08/04 09:19, , 5F
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
08/04 12:21, 9F
→
08/04 12:22, , 10F
08/04 12:22, 10F
→
08/04 12:22, , 11F
08/04 12:22, 11F
→
08/04 12:23, , 12F
08/04 12:23, 12F
→
08/04 12:23, , 13F
08/04 12:23, 13F
→
08/05 00:00, , 14F
08/05 00:00, 14F
→
08/05 00:01, , 15F
08/05 00:01, 15F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章