1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| #include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QSqlDatabase db = QSqlDatabase::addDatabase("QOCI");
db.setHostName("localhost:8080");
db.setDatabaseName("customdb"); // c'est quoi le nom ?
db.setUserName("******");
db.setPassword("*******");
if(!db.open())
ui->label->setText("Failed to open the database");
else
ui->label->setAcceptDrops("Connected...");
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
QString username,password;
username=ui->lineEdit_usernmae->text();
password=ui->lineEdit_password->text();
if(!db.isOpen()){
qDebug()<<"Failed to open the database";
return;
}
QSqlQuery qry;
if(qry.exec("select * from employeeinfo where username='"+username+"' and password='"+password+"'")){
int count=0;
while(qry.next()){
count++;
}
if(count==1)
ui->label->setText("usermane and password is correct");
if(count>1)
ui->label->setText("Duplicate usermane and password");
if(count<1)
ui->label->setText("usermane and password is not correct");
}
} |
Partager