I have a java code that works
//**Correct Java query**
QueryString = "INSERT IGNORE INTO stock_prices (symbol,timestamp,open,high,low,close,vol) VALUES ('"
+ data[0] + "', '" + data[1] + "', " + data[2] + ", " + data[3] + ", " + data[4] + ", "
+ data[5] + ", " + data[6] + ")";
However in java you can add double or int with string easily and in c++ you cannot, i’ve tried multiple things for the query in C++ but it isn’t working like i think it should. What am I doing wrong? Is there a better way in C++ to do this. Heres my query.
//***Incorrect C++ query**
sql::Statement *stmt;
stmt = con->createStatement();
for (int i = 0; i < (int)timestamp.size(); i++) {
string s = symbols[ii];
string t = timestamp[i];
double v = vwap[i];
string query = "INSERT INTO stock_prices(symbol,time_stamp,vwap) VALUES('" + s + "', '" + t + "', " + boost::lexical_cast<std::string>(v) + ")";
stmt->executeQuery(query);
}
The above code runs for 1 iteration of the for loop and then the following error is thrown
terminate called after throwing an instance of 'sql::SQLException'
what():
Aborted
I printed out the C++ query(which works if i copy paste it into mysql)
INSERT INTO stock_prices(symbol,time_stamp,vwap) VALUES('A', '2010-01-04 08:01:00', 0)
Shouldn’t you be using ‘ (single quote) on the remaining elements ?
Instead of this:
try this: