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.3k 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.
  • mrjjM Offline
    mrjjM Offline
    mrjj
    Lifetime Qt Champion
    wrote on last edited by
    #2

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

    1 Reply Last reply
    0
    • J JonnyQB

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

      JonBJ Online
      JonBJ Online
      JonB
      wrote on 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
      1
      • JonBJ JonB

        @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 last edited by
        #4

        @JonB
        after i fixed it i got the same thing

        JonBJ 1 Reply Last reply
        0
        • J JonnyQB

          @JonB
          after i fixed it i got the same thing

          JonBJ Online
          JonBJ Online
          JonB
          wrote on 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
          0
          • JonBJ JonB

            @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 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 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 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 JonBJ 2 Replies Last reply
                1
                • SGaistS SGaist

                  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 last edited by
                  #9

                  @SGaist
                  where should i set it it =1

                  1 Reply Last reply
                  0
                  • SGaistS SGaist

                    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.

                    JonBJ Online
                    JonBJ Online
                    JonB
                    wrote on 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 last edited by JonnyQB
                      #11

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

                      JonBJ 1 Reply Last reply
                      0
                      • J JonnyQB

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

                        JonBJ Online
                        JonBJ Online
                        JonB
                        wrote on 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
                        0
                        • JonBJ JonB

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

                          JonBJ 1 Reply Last reply
                          0
                          • J JonnyQB

                            @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

                            JonBJ Online
                            JonBJ Online
                            JonB
                            wrote on 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
                            0
                            • JonBJ JonB

                              @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 last edited by
                              #15

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

                              jsulmJ 1 Reply Last reply
                              0
                              • J JonnyQB

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

                                jsulmJ Offline
                                jsulmJ Offline
                                jsulm
                                Lifetime Qt Champion
                                wrote on 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 last edited by
                                  #17

                                  @JonB @jsulm

                                  Unbenannt6.PNG

                                  JonBJ 1 Reply Last reply
                                  0
                                  • J JonnyQB

                                    @JonB @jsulm

                                    Unbenannt6.PNG

                                    JonBJ Online
                                    JonBJ Online
                                    JonB
                                    wrote on 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