SQLITE数据库 

发表于:2013-04-22来源:Csdn作者:FreeBeer点击数: 标签:SQLServer
[cpp] view plaincopyprint? QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");

  [cpp] view plaincopyprint?

  QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");

  db.setDatabaseName("support");

  if(!db.open())

  {

  QMessageBox::critical(0, qApp->tr("Cannot open database"),

  qApp->tr("Unable to establish a database connection.\n"

  "This example needs SQLite support. Please read "

  "the Qt SQL driver documentation for information how "

  "to build it.\n\n"

  "Click Cancel to exit."), QMessageBox::Cancel);

  return false;

  }

  QSqlQuery q;

  q.exec("create table student(id integer primary key,name varchar,age integer)");

  q.exec("insert into student(id,name,age) values(1001,'AnPan',21)");

  q.exec("insert into student(id,name,age) values(1002,'CaoLL',22)");

  return true;

  QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");

  db.setDatabaseName("support");

  if(!db.open())

  {

  QMessageBox::critical(0, qApp->tr("Cannot open database"),

  qApp->tr("Unable to establish a database connection.\n"

  "This example needs SQLite support. Please read "

  "the Qt SQL driver documentation for information how "

  "to build it.\n\n"

  "Click Cancel to exit."), QMessageBox::Cancel);

  return false;

  }

  QSqlQuery q;

  q.exec("create table student(id integer primary key,name varchar,age integer)");

  q.exec("insert into student(id,name,age) values(1001,'AnPan',21)");

  q.exec("insert into student(id,name,age) values(1002,'CaoLL',22)");

  return true;

原文转自:http://www.ltesting.net