I wrote a program which is reading all the time data from a table in a loop
try{
sql::Driver *driver;
sql::Connection *con;
sql::Statement *stmt;
sql::ResultSet *res;
driver = get_driver_instance();
con = driver->connect("localhost:3306", "root", "");
con->setSchema("bgame");
stmt = con->createStatement();
while(1){
stmt = con->createStatement();
sprintf(sql_query, "SELECT * FROM buildquery WHERE zeit<=%d Order by zeit DESC",time(NULL));
res = stmt->executeQuery(sql_query);
while (res->next()) {
// ... edit some results -> get sz,sz2,sz3,sz4 (they are correct) ...
sprintf(sql_up_query, "Update villages Set %s=%s+1 Where vid='%s' ",sz2,sz2,sz);
stmt->executeQuery(sql_up_query);
sprintf(sql_del_query, "Delete from buildquery Where id=%s ",sz4);
stmt->executeQuery(sql_del_query);
}
}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;
}
-------
The querys work and the first updates the table
but after that I get an error :
#ERR: SQLException in .\buildquery.cpp(main) on line 164
#ERR: (MySQL error code: 0, SQLState: 00000
and the program stop reading and editing the table
How can I do it right?
Sorry for my bad english - I´m german ;)