Mysql resultset is empty?

EDIT

Next question: mysql result set is always zero

-

resultsetseems empty and I'm sure the table exists, no SQLException. He must print the invoice, but that is not so.

Database header

class CDatabase
{
    bool verify(string, string);
public:
    sql::Connection *con;
    CDatabase();
    ~CDatabase();
};

CDatabase :: CDatabase

con = driver->connect("", "", "");
con->setSchema("");

CDatabase :: check

bool CDatabase::verify(string channel, string hyper_key)
{
    if (!con) return false;
    try
    {
        sql::Statement *stmt;
        sql::ResultSet *res;
        stmt = con->createStatement();
        stmt->execute("SELECT COUNT(*) FROM dark_souls2_widgets");
        res = stmt->getResultSet();
        cout << res->rowsCount();
        delete stmt;
        delete res;
    }
    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;
        return false;
    }
    return false;
}
0
source share
2 answers

It should not show the counter, it should show 1, because this request will either fail, or the result will have only one line. If you want to know how many rows exist in your table dark_souls2_widgets, you can do this with

res = stmt->getResultSet();

while (res->next()) {
  cout << res->getInt(1); // getInt(1) returns the first column
}
+2
source

mysql ++ , ... dev.mysql

stmt = con->createStatement();
res = stmt->executeQuery("SELECT 'Hello World!' AS _message");
while (res->next()) {
    cout << "\t... MySQL replies: ";
    /* Access column data by alias or column name */
    cout << res->getString("_message") << endl;
    cout << "\t... MySQL says it again: ";
    /* Access column fata by numeric offset, 1 is the first column */
    cout << res->getString(1) << endl;
}

, execute() executeQuery(). , rowsCount() 1 , , , . .

stmt->executeQuery("SELECT COUNT(*) FROM dark_souls2_widgets");
res = stmt->getResultSet();
while (res->next()) {
    cout << res->getInt(1);
}

,

stmt->executeQuery("SELECT * FROM dark_souls2_widgets");
cout << res->rowsCount();

-

stmt = con->creteStatement()
res = stmt->executeQuery("SELECT COUNT(*) FROM dark_souls2_widgets");
while (res->next()) {
    cout << res->getInt(1);
}
+1

All Articles