Quantcast
Channel: MySQL Forums - Connector/C++
Viewing all articles
Browse latest Browse all 527

Prepared Statements: setInt always 0 (no replies)

$
0
0
Hi!

first of all i have to exuse me for my english! obviously i want to access my database with c++. I downloded the "mysql-connector-c++-1.1.2.tar" and compiled it with cmake and msvc2010. then i copied the example code [*] form the mysql homepage.

After starting the programm, i can connect to my database test and create the table test_table. I can also insert entrys with the prepareStatement, but all entrys have the value 0.

Any ideas on why I can't bind to the prepared statement?

thx for your help


[*]


#include "stdafx.h"

#include "mysql_connection.h"

#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>
#include <cppconn/prepared_statement.h>

int _tmain(int argc, _TCHAR* argv[])
{
sql::Driver *driver;
sql::Connection *con;
sql::Statement *stmt;
sql::ResultSet *res;
sql::PreparedStatement *pstmt;

driver = get_driver_instance();
con = driver->connect("tcp://127.0.0.1:3306", "root", "");

con->setSchema("test");

stmt = con->createStatement();
stmt->execute("DROP TABLE IF EXISTS test");
stmt->execute("CREATE TABLE test_table(id INT)");
delete stmt;

/* '?' is the supported placeholder syntax */

pstmt = con->prepareStatement("INSERT INTO test_table(id) VALUES (?)");
for (int i = 1; i <= 10; i++) {
pstmt->setInt(1, i);
pstmt->executeUpdate();
}

delete pstmt;
delete con;

return 0;
}

Viewing all articles
Browse latest Browse all 527

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>