I have connected to PostgreSQL database successfully but I can not seem to query it I have tried several queries but keep facing with this error.
Connection Successful
QSqlError("42601", "QPSQL: Unable to create query", "ERROR: syntax error at
end of input\nLINE 1: EXECUTE \n ^\n(42601)")
My code
void MainWindow::connection()
{
QSqlDatabase db;
db = QSqlDatabase::addDatabase("QPSQL");
db.setHostName("localhost");
db.setDatabaseName("postgres");
db.setUserName("postgres");
db.setPassword("xxx");
db.setPort(5433);
if (db.open())
qDebug() << "Connection Successful";
else
qDebug() << "Connection Failed!";
}
void MainWindow::query()
{
QSqlQuery query("select * from company");
if( !query.exec())
qDebug() << query.lastError();
else
{
while(query.next())
{
qDebug() << query.value(0).toString();
ui->label_2->setText(query.value(0).toString());
}
}
}
can anyone please enlighten me