重慶分公司,新征程啟航
為企業(yè)提供網(wǎng)站建設、域名注冊、服務器等服務
為企業(yè)提供網(wǎng)站建設、域名注冊、服務器等服務
QtSql模塊提供了與平臺以及數(shù)據(jù)庫種類無關的訪問SQL數(shù)據(jù)庫的接口,這個接口由利用Qt的模型視圖結構將數(shù)據(jù)庫與用戶界面集成的一套類來支持。
QSqlDatabase對象象征了數(shù)據(jù)庫的關聯(lián)。Qt使用驅動程序與各種數(shù)據(jù)庫的應用編程接口進行通信。Qt的桌面版(Desktop Edition)包括如下一些驅動程序:
驅動程序數(shù)據(jù)庫
QDB2IBM DB2 7.1版以及更新的版本
QIBASEBorland InterBase
QMySQLMySql
QOCI甲骨文公司(Oracle Call Interface)
QODBC ODBC(包括微軟公司的QSL服務)
QPSQL PostgreSQL的7.3版以及更高版本
QSQLITEQSLite第3版
QSQLITE2QSLite第2版
為豐順等地區(qū)用戶提供了全套網(wǎng)頁設計制作服務,及豐順網(wǎng)站建設行業(yè)解決方案。主營業(yè)務為成都網(wǎng)站建設、網(wǎng)站制作、豐順網(wǎng)站設計,以傳統(tǒng)方式定制建設網(wǎng)站,并提供域名空間備案等一條龍服務,秉承以專業(yè)、用心的態(tài)度為用戶提供真誠的服務。我們深信只要達到每一位用戶的要求,就會得到認可,從而選擇與我們長期合作。這樣,我們也可以走得更遠!
QTDS Qybase自適應服務器
[cpp] view plain copy print?
#include
#include
#include
#include
#include
#include
#include
#include
#include
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QSqlDatabase database = QSqlDatabase::addDatabase("QSQLITE");
database.setDatabaseName("CashSystem.db");
if(database.open())
{
qDebug()<<"Database Opened";
QSqlQuery sql_query;
QString create_sql = "create table member (id int primary key, name varchar(30), address varchar(30))"; //創(chuàng)建數(shù)據(jù)表
QString insert_sql = "insert into member values(?,?,?)"; //插入數(shù)據(jù)
QString select_all_sql = "select * from member";
sql_query.prepare(create_sql); //創(chuàng)建表
if(!sql_query.exec()) //查看創(chuàng)建表是否成功
{
qDebug()<
qDebug()<
}
else
{
qDebug()<< "Table Created" ;
//插入數(shù)據(jù)
sql_query.prepare(insert_sql);
QVariantList GroupIDs;
GroupIDs.append(0);
GroupIDs.append(1);
GroupIDs.append(2);
QVariantList GroupNames;
GroupNames.append("hsp");
GroupNames.append("rl");
GroupNames.append("spl");
QVariantList GroupAddress;
GroupAddress.append("南充");
GroupAddress.append("寶雞");
GroupAddress.append("南充");
sql_query.addBindValue(GroupIDs);
sql_query.addBindValue(GroupNames);
sql_query.addBindValue(GroupAddress);
if(!sql_query.execBatch())
{
qDebug()<
}
else
{
qDebug()<<"插入記錄成功";
}
//查詢所有記錄
sql_query.prepare(select_all_sql);
if(!sql_query.exec())
{
qDebug()<
}
else
{
while(sql_query.next())
{
int id = sql_query.value(0).toInt();
QString name = sql_query.value(1).toString();
QString address = sql_query.value(2).toString();
qDebug()<
}
}
}
}
database.close();
// QFile::remove("CashSystem.db");
return a.exec();
}