Hey guys,
I am pretty new to c++, and I am currently writing a program, which should use prepared statements to insert a specific value into the database.
So, if I run this programm, I just get a "0, 0" in my database, and not ANY of these:
prep_stmt->setInt(1, 1);
prep_stmt->setString(2, "a");
prep_stmt->setInt(1, 2);
prep_stmt->setString(2, "b");
Why it doesn't work?
I just don't get it...
Thank you very much,
Paul
I am pretty new to c++, and I am currently writing a program, which should use prepared statements to insert a specific value into the database.
int main(void) { cout << endl; cout << "Testblablablablalbal" << endl; try { sql::Driver *driver; sql::Connection *con; sql::PreparedStatement *prep_stmt; driver = get_driver_instance(); con = driver->connect("tcp://127.0.0.1:3306", "test", "user"); // Connect to the MySQL test database con->setSchema("test"); prep_stmt = con->prepareStatement("INSERT INTO test(id, label) VALUES (?, ?)"); prep_stmt->setInt(1, 1); prep_stmt->setString(2, "a"); prep_stmt->execute(); prep_stmt->setInt(1, 2); prep_stmt->setString(2, "b"); prep_stmt->execute(); delete prep_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; system("PAUSE"); return EXIT_SUCCESS; }
So, if I run this programm, I just get a "0, 0" in my database, and not ANY of these:
prep_stmt->setInt(1, 1);
prep_stmt->setString(2, "a");
prep_stmt->setInt(1, 2);
prep_stmt->setString(2, "b");
Why it doesn't work?
I just don't get it...
Thank you very much,
Paul