3
query->prepare("INSERT INTO businessweek (id, source, date, headline, body) VALUES (NULL, ?, ?, ?, ?)");
query->bindValue(1, "source");
query->bindValue(2, "date");
query->bindValue(3, "headline");
query->bindValue(4, "body");

if (query->exec()) {
    tt << "Query success";
} else {
    qDebug() << db.lastError();
    return;
}

I'm using QMYSQL. And the error is

 QSqlError(-1, "", "") 

But

query->exec("INSERT INTO businessweek (id, source, date, headline, body) VALUES (NULL, 'google', 'may 0, 23', 'head', 'fjsdflksjdlkfdsjlfkjd');")

is working fine.

Dewsworld
  • 13,367
  • 23
  • 68
  • 104

1 Answers1

3

It is hard to guess the problem. But one thing I could imagine and that definitely is wrong with your code is that field numbering for bindValue starts at 0 (see here).

Thus, I would suggest to try

query->prepare("INSERT INTO businessweek (id, source, date, headline, body) VALUES (NULL, ?, ?, ?, ?)");
query->bindValue(0, "source");
query->bindValue(1, "date");
query->bindValue(2, "headline");
query->bindValue(3, "body");

if (query->exec()) {
    tt << "Query success";
} else {
    qDebug() << db.lastError();
    return;
}
Thilo
  • 8,827
  • 2
  • 35
  • 56