Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. cannot Excecute query in sql
Forum Updated to NodeBB v4.3 + New Features

cannot Excecute query in sql

Scheduled Pinned Locked Moved Unsolved General and Desktop
18 Posts 5 Posters 1.2k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    JonnyQB
    wrote on 14 Sept 2020, 11:38 last edited by
    #1

    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;
    }

    J 1 Reply Last reply 14 Sept 2020, 11:53
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 14 Sept 2020, 11:44 last edited by
      #2

      Hi
      Try to see if it has some error information using query.lastError()

      1 Reply Last reply
      0
      • J JonnyQB
        14 Sept 2020, 11:38

        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;
        }

        J Offline
        J Offline
        JonB
        wrote on 14 Sept 2020, 11:53 last edited by
        #3

        @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 for Username=:username. Please try to look at your code before posting a question on it.

        J 1 Reply Last reply 14 Sept 2020, 11:58
        1
        • J JonB
          14 Sept 2020, 11:53

          @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 for Username=:username. Please try to look at your code before posting a question on it.

          J Offline
          J Offline
          JonnyQB
          wrote on 14 Sept 2020, 11:58 last edited by
          #4

          @JonB
          after i fixed it i got the same thing

          J 1 Reply Last reply 14 Sept 2020, 12:06
          0
          • J JonnyQB
            14 Sept 2020, 11:58

            @JonB
            after i fixed it i got the same thing

            J Offline
            J Offline
            JonB
            wrote on 14 Sept 2020, 12:06 last edited by JonB
            #5

            @JonnyQB
            Start by printing out query.lastError() after executing statement, as @mrjj said. Almost anything could be the issue. You do not even say what message you get from your code, only "i just cant execute the query". There is also no message for Logindb.open() failing. We cannot guess.

            J 1 Reply Last reply 14 Sept 2020, 12:24
            0
            • J JonB
              14 Sept 2020, 12:06

              @JonnyQB
              Start by printing out query.lastError() after executing statement, as @mrjj said. Almost anything could be the issue. You do not even say what message you get from your code, only "i just cant execute the query". There is also no message for Logindb.open() failing. We cannot guess.

              J Offline
              J Offline
              JonnyQB
              wrote on 14 Sept 2020, 12:24 last edited by
              #6

              @JonB
              Error = "Driver not loaded Driver not loaded"
              now should i use another driver or what ?

              1 Reply Last reply
              0
              • J Offline
                J Offline
                JonnyQB
                wrote on 14 Sept 2020, 12:46 last edited by
                #7

                @JonB
                both sqllite and mysql are not loaded

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 14 Sept 2020, 18:23 last edited by
                  #8

                  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.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  J J 2 Replies Last reply 15 Sept 2020, 12:29
                  1
                  • SGaistS SGaist
                    14 Sept 2020, 18:23

                    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.

                    J Offline
                    J Offline
                    JonnyQB
                    wrote on 15 Sept 2020, 12:29 last edited by
                    #9

                    @SGaist
                    where should i set it it =1

                    1 Reply Last reply
                    0
                    • SGaistS SGaist
                      14 Sept 2020, 18:23

                      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.

                      J Offline
                      J Offline
                      JonB
                      wrote on 15 Sept 2020, 12:50 last edited by
                      #10

                      @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.

                      1 Reply Last reply
                      0
                      • J Offline
                        J Offline
                        JonnyQB
                        wrote on 15 Sept 2020, 13:31 last edited by JonnyQB
                        #11

                        @JonB
                        @SGaist
                        like so ?
                        it changes nothing
                        Unbenannt4.PNG

                        J 1 Reply Last reply 15 Sept 2020, 17:19
                        0
                        • J JonnyQB
                          15 Sept 2020, 13:31

                          @JonB
                          @SGaist
                          like so ?
                          it changes nothing
                          Unbenannt4.PNG

                          J Offline
                          J Offline
                          JonB
                          wrote on 15 Sept 2020, 17:19 last edited by JonB
                          #12

                          @JonnyQB
                          Please take the time to read @SGaist's post; it's also in the Qt documentation. You have not spelled the environment variable as he typed, you have not used copy & paste, so what do you expect to happen if you do not get that correct?

                          J 1 Reply Last reply 16 Sept 2020, 18:21
                          0
                          • J JonB
                            15 Sept 2020, 17:19

                            @JonnyQB
                            Please take the time to read @SGaist's post; it's also in the Qt documentation. You have not spelled the environment variable as he typed, you have not used copy & paste, so what do you expect to happen if you do not get that correct?

                            J Offline
                            J Offline
                            JonnyQB
                            wrote on 16 Sept 2020, 18:21 last edited by
                            #13

                            @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

                            J 1 Reply Last reply 16 Sept 2020, 19:18
                            0
                            • J JonnyQB
                              16 Sept 2020, 18:21

                              @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

                              J Offline
                              J Offline
                              JonB
                              wrote on 16 Sept 2020, 19:18 last edited by JonB
                              #14

                              @JonnyQB
                              To be clear: you are changing in the right place (I think!), but the name must be QT_DEBUG_PLUGINS, OK?

                              J 1 Reply Last reply 29 Sept 2020, 10:48
                              0
                              • J JonB
                                16 Sept 2020, 19:18

                                @JonnyQB
                                To be clear: you are changing in the right place (I think!), but the name must be QT_DEBUG_PLUGINS, OK?

                                J Offline
                                J Offline
                                JonnyQB
                                wrote on 29 Sept 2020, 10:48 last edited by
                                #15

                                @JonB
                                i changed it and got Error = "Driver not loaded Driver not loaded" again

                                jsulmJ 1 Reply Last reply 29 Sept 2020, 10:51
                                0
                                • J JonnyQB
                                  29 Sept 2020, 10:48

                                  @JonB
                                  i changed it and got Error = "Driver not loaded Driver not loaded" again

                                  jsulmJ Offline
                                  jsulmJ Offline
                                  jsulm
                                  Lifetime Qt Champion
                                  wrote on 29 Sept 2020, 10:51 last edited by
                                  #16

                                  @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).

                                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                                  1 Reply Last reply
                                  0
                                  • J Offline
                                    J Offline
                                    JonnyQB
                                    wrote on 29 Sept 2020, 12:23 last edited by
                                    #17

                                    @JonB @jsulm

                                    Unbenannt6.PNG

                                    J 1 Reply Last reply 29 Sept 2020, 12:25
                                    0
                                    • J JonnyQB
                                      29 Sept 2020, 12:23

                                      @JonB @jsulm

                                      Unbenannt6.PNG

                                      J Offline
                                      J Offline
                                      JonB
                                      wrote on 29 Sept 2020, 12:25 last edited by
                                      #18

                                      @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....

                                      1 Reply Last reply
                                      0

                                      • Login

                                      • Login or register to search.
                                      • First post
                                        Last post
                                      0
                                      • Categories
                                      • Recent
                                      • Tags
                                      • Popular
                                      • Users
                                      • Groups
                                      • Search
                                      • Get Qt Extensions
                                      • Unsolved