Unsolved cannot Excecute query in sql
-
i just cant execute the query
databaseconnection:
QSqlDatabase Logindb=QSqlDatabase::addDatabase("QMYSQL","MyConnect");
Logindb.setHostName("127.0.0.1");
Logindb.setPort(3306);
Logindb.setDatabaseName("agr_kako");
Logindb.setUserName("root");
Logindb.setPassword("1234");on pushbutton:
QString username,passwort; username=ui->lineEdit_User->text(); passwort=ui->lineEdit_Password->text(); QSqlQuery qry(QSqlDatabase::database("MyConnect")); if(Logindb.open()) { QSqlQuery qry(QSqlDatabase::database("MyConnect")); qry.prepare(QString("SELECT * FROM login WHERE Username=:username and Password :passwort ")); qry.bindValue(":username",username); qry.bindValue(":passwort",passwort); if(!qry.exec()){ QMessageBox::information(this,"Failed","Query Failed to Execute"); } else { while(qry.next()){ QString usernameFromDB=qry.value(1).toString(); QString passwordFromDB=qry.value(2).toString(); if(username==username&& passwordFromDB==passwort) {QMessageBox::information(this,"Success","Login Erfolgreich"); parameter=new Parameter(this); parameter->show(); hide(); } else { QMessageBox::information(this,"Fehler","Name oder Passwort falsch");} } } }
// if(Logindb.open()){
// if(qry.exec("Select * from login where Username='"+username+"'and Password'"+passwort+"'"))
// {
// int count=0;
// while(qry.next())
// {// count++;
// }
// if(count==1)
// ui->label_3->setText("Login erfolgreich");
// if(count>1)
// ui->label_3->setText("");
// if(count==1)
// ui->label_3->setText("Login fehlgeschlagen Passwort oder Name falsch");
// }
// }
else
{
QMessageBox::information(this,"Failed","Query Failed to Execute");
return;
} -
Hi
Try to see if it has some error information using query.lastError() -
@JonnyQB said in cannot Excecute query in sql:
qry.prepare(QString("SELECT * FROM login WHERE Username=:username and Password :passwort "));
You mean
Password=:passwort
, just like you did forUsername=:username
. Please try to look at your code before posting a question on it. -
@JonB
after i fixed it i got the same thing -
-
@JonB
Error = "Driver not loaded Driver not loaded"
now should i use another driver or what ? -
@JonB
both sqllite and mysql are not loaded -
Hi,
Start your application with QT_DEBUG_PLUGINS environment variable set to 1 so see what happens when the plugins are loaded.
You can set that variable in the Run part of the Project panel.
-
@SGaist
where should i set it it =1 -
@JonnyQB
Did you see:@SGaist said in cannot Excecute query in sql:
You can set that variable in the Run part of the Project panel.
-
-
-
@JonB
i took time to read and figure it out but i couldnt find it because i think my qt is german soi dont know where to chage it exactly -
@JonnyQB
To be clear: you are changing in the right place (I think!), but the name must beQT_DEBUG_PLUGINS
, OK? -
@JonB
i changed it and got Error = "Driver not loaded Driver not loaded" again -
@JonnyQB With QT_DEBUG_PLUGINS set you should now get some additional output from the application. You have to check that output to see why the plug-in was not loaded (you can also post it here).
-
-
@JonnyQB
We have said repeatedly what you need to set to get the debug output required in the replies above. Show us where you did what for that and we will look again....