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.

0

1 Answer 1

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;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.