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. No data supplied for parameters in prepared statement"

No data supplied for parameters in prepared statement"

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 2 Posters 1.6k Views 1 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.
  • A Offline
    A Offline
    arcahyadi
    wrote on last edited by
    #1

    Hello

    im new to qt and C++

    im trying to insert data from UI to database, im following db connection and sql executing from documentation
    error no data supplied keep show up if using placeholder

    if i do it direcly (no input from ui) like this

     if (!sql.exec("INSERT INTO karyawan (nik,nama,alamat,telp,golongan,status,anak,masa,gaji)"
                    "VALUE('1001542','anwar','BJM','085149','I','menikah','1','2','3200000')")){
            qDebug()<<sql.lastError().text();
        }else{
            qDebug()<<"Data Berhasil Disimpan";
        }
    
    

    its success or using single quotes between placeholder
    but the problem using single quotes is the data inserted is the name of placeholder not the data

    sql.prepare("INSERT INTO karyawan (nik,nama,alamat,telp,golongan,status,anak,masa,gaji)"
                  "VALUE(':nik',':nama',':alamat',':telp',':golongan',':status',':anak',':masa',':gaji')");
    
    data inserted 
    

    0b502e48-9740-44c6-91c5-3ac5c41ab1e3-image.png

    QSqlDatabase koneksi = QSqlDatabase::addDatabase("QODBC");
        koneksi.setDatabaseName("dsn_penggajian");
        koneksi.setUserName("root");
        koneksi.setPassword("");
    
        if(!koneksi.open()){
            qDebug()<<koneksi.lastError().text();
        }else{
            qDebug()<<"Database Terkoneksi";
    
        }
    
    QSqlQuery sql(koneksi);
        sql.prepare("INSERT INTO karyawan (nik, nama, alamat, telp, golongan, status, anak, masa, gaji) "
                    "VALUES (:nik, :nama, :alamat, :telp, :golongan, :status, :anak, :masa, :gaji)");
        sql.bindValue(":nik", ui->nIKLineEdit->text());
        sql.bindValue(":nama", ui->namaLineEdit->text());
        sql.bindValue(":alamat", ui->alamatLineEdit->text());
        sql.bindValue(":telp", ui->telpLineEdit->text());
        sql.bindValue(":golongan", ui->golonganComboBox->currentText());
        sql.bindValue(":status", ui->statusNikahComboBox->currentText());
        sql.bindValue(":anak", ui->jumlahAnakLineEdit->text().toInt());
        sql.bindValue(":masa", ui->masaKerjaLineEdit->text().toInt());
        sql.bindValue(":gaji", uji.getGajiTotal());
        sql.exec();
        if (sql.exec()){
                qDebug()<<"Data Berhasil Disimpan"
            }else{
                qDebug()<<sql.lastError().text();
                qDebug()<<sql.executedQuery();
                qDebug() << "nik:" << ui->nIKLineEdit->text();
                qDebug() << "nama:" << ui->namaLineEdit->text()
                qDebug() << "alamat:" << ui->alamatLineEdit->text();
                qDebug() << "telp:" << ui->telpLineEdit->text();
                qDebug() << "golongan:" << ui->golonganComboBox->currentText();
                qDebug() << "status:" << ui->statusNikahComboBox->currentText();
                qDebug() << "anak:" << ui->jumlahAnakLineEdit->text().toInt()
                qDebug() << "masa:" << ui->masaKerjaLineEdit->text().toInt();
                qDebug() << "gaji:" << uji.getGajiTotal();
            }
    
    DEBUG HERE
    Database Terkoneksi
    "QODBCResult::exec: Unable to execute statement:" 	Error: "[MySQL][ODBC 8.4(w) Driver][mysqld-5.5.5-10.4.32-MariaDB]No data supplied for parameters in prepared statement"
    "QODBCResult::exec: Unable to execute statement:" 	Error: "[MySQL][ODBC 8.4(w) Driver][mysqld-5.5.5-10.4.32-MariaDB]No data supplied for parameters in prepared statement"
    "[MySQL][ODBC 8.4(w) Driver][mysqld-5.5.5-10.4.32-MariaDB]No data supplied for parameters in prepared statement, S1000 QODBC: Unable to execute statement"
    "INSERT INTO karyawan (nik, nama, alamat, telp, golongan, status, anak, masa, gaji) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"
    QSqlDatabase(driver="QODBC", database="dsn_penggajian", host="", port=-1, user="root", open=true)
    nik: "9348"
    nama: "iuweweui"
    alamat: "eiweu"
    telp: "929390"
    golongan: "I"
    status: "Menikah"
    anak: 1212
    masa: 1212
    gaji: 5000000
    
    
    Christian EhrlicherC 1 Reply Last reply
    0
    • Christian EhrlicherC Christian Ehrlicher

      @arcahyadi said in No data supplied for parameters in prepared statement":

      sql.exec();
      if (sql.exec()){
      

      You call exec twice...

      A Offline
      A Offline
      arcahyadi
      wrote on last edited by
      #9

      @Christian-Ehrlicher fixed, im used old mysql, update mysql and the problem clear

      1 Reply Last reply
      0
      • Christian EhrlicherC Online
        Christian EhrlicherC Online
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #2

        Don't use any quotes at all for prepared values as shown in the documentation.

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        A 1 Reply Last reply
        0
        • Christian EhrlicherC Christian Ehrlicher

          Don't use any quotes at all for prepared values as shown in the documentation.

          A Offline
          A Offline
          arcahyadi
          wrote on last edited by
          #3

          @Christian-Ehrlicher

          yeah but show error "No data supplied for parameters in prepared statement"

          4686520a-e634-4178-9f81-534264f66744-image.png

          1 Reply Last reply
          0
          • Christian EhrlicherC Online
            Christian EhrlicherC Online
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by Christian Ehrlicher
            #4

            prepare() has a return value - check it, same goes for sql.exec();

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            A 2 Replies Last reply
            0
            • Christian EhrlicherC Christian Ehrlicher

              prepare() has a return value - check it, same goes for sql.exec();

              A Offline
              A Offline
              arcahyadi
              wrote on last edited by
              #5

              @Christian-Ehrlicher

              its give return true
              d3dc2eb5-5870-4583-985f-c1e24beb6747-image.png

              1 Reply Last reply
              0
              • Christian EhrlicherC Christian Ehrlicher

                prepare() has a return value - check it, same goes for sql.exec();

                A Offline
                A Offline
                arcahyadi
                wrote on last edited by
                #6

                @Christian-Ehrlicher sorry typo, prepare return true and exec return false

                1 Reply Last reply
                0
                • Christian EhrlicherC Online
                  Christian EhrlicherC Online
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by Christian Ehrlicher
                  #7

                  Please provide a minimal compileable example including the creation of the table. Should be doable with less than 20 lines of code. What exact Qt version do you use?

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  1 Reply Last reply
                  0
                  • A arcahyadi

                    Hello

                    im new to qt and C++

                    im trying to insert data from UI to database, im following db connection and sql executing from documentation
                    error no data supplied keep show up if using placeholder

                    if i do it direcly (no input from ui) like this

                     if (!sql.exec("INSERT INTO karyawan (nik,nama,alamat,telp,golongan,status,anak,masa,gaji)"
                                    "VALUE('1001542','anwar','BJM','085149','I','menikah','1','2','3200000')")){
                            qDebug()<<sql.lastError().text();
                        }else{
                            qDebug()<<"Data Berhasil Disimpan";
                        }
                    
                    

                    its success or using single quotes between placeholder
                    but the problem using single quotes is the data inserted is the name of placeholder not the data

                    sql.prepare("INSERT INTO karyawan (nik,nama,alamat,telp,golongan,status,anak,masa,gaji)"
                                  "VALUE(':nik',':nama',':alamat',':telp',':golongan',':status',':anak',':masa',':gaji')");
                    
                    data inserted 
                    

                    0b502e48-9740-44c6-91c5-3ac5c41ab1e3-image.png

                    QSqlDatabase koneksi = QSqlDatabase::addDatabase("QODBC");
                        koneksi.setDatabaseName("dsn_penggajian");
                        koneksi.setUserName("root");
                        koneksi.setPassword("");
                    
                        if(!koneksi.open()){
                            qDebug()<<koneksi.lastError().text();
                        }else{
                            qDebug()<<"Database Terkoneksi";
                    
                        }
                    
                    QSqlQuery sql(koneksi);
                        sql.prepare("INSERT INTO karyawan (nik, nama, alamat, telp, golongan, status, anak, masa, gaji) "
                                    "VALUES (:nik, :nama, :alamat, :telp, :golongan, :status, :anak, :masa, :gaji)");
                        sql.bindValue(":nik", ui->nIKLineEdit->text());
                        sql.bindValue(":nama", ui->namaLineEdit->text());
                        sql.bindValue(":alamat", ui->alamatLineEdit->text());
                        sql.bindValue(":telp", ui->telpLineEdit->text());
                        sql.bindValue(":golongan", ui->golonganComboBox->currentText());
                        sql.bindValue(":status", ui->statusNikahComboBox->currentText());
                        sql.bindValue(":anak", ui->jumlahAnakLineEdit->text().toInt());
                        sql.bindValue(":masa", ui->masaKerjaLineEdit->text().toInt());
                        sql.bindValue(":gaji", uji.getGajiTotal());
                        sql.exec();
                        if (sql.exec()){
                                qDebug()<<"Data Berhasil Disimpan"
                            }else{
                                qDebug()<<sql.lastError().text();
                                qDebug()<<sql.executedQuery();
                                qDebug() << "nik:" << ui->nIKLineEdit->text();
                                qDebug() << "nama:" << ui->namaLineEdit->text()
                                qDebug() << "alamat:" << ui->alamatLineEdit->text();
                                qDebug() << "telp:" << ui->telpLineEdit->text();
                                qDebug() << "golongan:" << ui->golonganComboBox->currentText();
                                qDebug() << "status:" << ui->statusNikahComboBox->currentText();
                                qDebug() << "anak:" << ui->jumlahAnakLineEdit->text().toInt()
                                qDebug() << "masa:" << ui->masaKerjaLineEdit->text().toInt();
                                qDebug() << "gaji:" << uji.getGajiTotal();
                            }
                    
                    DEBUG HERE
                    Database Terkoneksi
                    "QODBCResult::exec: Unable to execute statement:" 	Error: "[MySQL][ODBC 8.4(w) Driver][mysqld-5.5.5-10.4.32-MariaDB]No data supplied for parameters in prepared statement"
                    "QODBCResult::exec: Unable to execute statement:" 	Error: "[MySQL][ODBC 8.4(w) Driver][mysqld-5.5.5-10.4.32-MariaDB]No data supplied for parameters in prepared statement"
                    "[MySQL][ODBC 8.4(w) Driver][mysqld-5.5.5-10.4.32-MariaDB]No data supplied for parameters in prepared statement, S1000 QODBC: Unable to execute statement"
                    "INSERT INTO karyawan (nik, nama, alamat, telp, golongan, status, anak, masa, gaji) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"
                    QSqlDatabase(driver="QODBC", database="dsn_penggajian", host="", port=-1, user="root", open=true)
                    nik: "9348"
                    nama: "iuweweui"
                    alamat: "eiweu"
                    telp: "929390"
                    golongan: "I"
                    status: "Menikah"
                    anak: 1212
                    masa: 1212
                    gaji: 5000000
                    
                    
                    Christian EhrlicherC Online
                    Christian EhrlicherC Online
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on last edited by
                    #8

                    @arcahyadi said in No data supplied for parameters in prepared statement":

                    sql.exec();
                    if (sql.exec()){
                    

                    You call exec twice...

                    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                    Visit the Qt Academy at https://academy.qt.io/catalog

                    A 1 Reply Last reply
                    4
                    • Christian EhrlicherC Christian Ehrlicher

                      @arcahyadi said in No data supplied for parameters in prepared statement":

                      sql.exec();
                      if (sql.exec()){
                      

                      You call exec twice...

                      A Offline
                      A Offline
                      arcahyadi
                      wrote on last edited by
                      #9

                      @Christian-Ehrlicher fixed, im used old mysql, update mysql and the problem clear

                      1 Reply Last reply
                      0
                      • A arcahyadi has marked this topic as solved on

                      • Login

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