#include #include #include #include #include #include /* * table for testcase created as * mysql> CREATE TABLE test_table (mykey int PRIMARY KEY, value double); * mysql> INSERT INTO test_table VALUES(1, 2.5); * * locale seting of database is en_US */ using namespace std; int main() { setlocale (LC_NUMERIC, "de_DE.UTF-8"); // use this to see the difference // setlocale (LC_NUMERIC, "en_US.UTF-8"); sql::Driver *myDriver=NULL; sql::Connection *myCon=NULL; sql::Statement *myStmt=NULL; sql::ResultSet *myRes=NULL; sql::ConnectOptionsMap myConnProps; double test_val; string slctStmnt = "SELECT value FROM test_table WHERE mykey=1;"; myConnProps["hostName"] = "localhost"; myConnProps["port"] = 3306 ; myConnProps["userName"] = "EXCHANGE_FOR_ACTUAL_USERNAME"; myConnProps["schema"] = "test"; myConnProps["OPT_READ_TIMEOUT"] = 10; try { myDriver = get_driver_instance(); myCon = myDriver->connect(myConnProps); myStmt = myCon->createStatement(); } catch (sql::SQLException err) { //include some error handler, if u like exit(-1); } try { myRes = myStmt->executeQuery(slctStmnt);; } catch (sql::SQLException err) { //include some error handler, if u like exit(-1); } myRes->next(); test_val = myRes->getDouble(1); cout << test_val << endl; return 0; }