petek, 07. maj 2010

Access DB2 via ODBC on Linux

This is how to install ODBC on Linux (Kubuntu 10.04) and access it.
Steps:
- install DB2 (I always install everything)
- install unixODBC
- edit $HOME/.odbc.ini :
[DB_NAME]
Description = Connection to DB_NAME
Driver=$HOME/sqllib/lib/libdb2.so

- run db2ca and add DB_NAME (don't forget to add ODBC)
- now you can use it on Qt for example like this:
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
db.setDatabaseName("DB_NAME");
db.setUserName("DB_USER");
db.setPassword("DB_PASS");
db.open();
QSqlError error = db.lastError();
qDebug() << "db error = " << error;

QSqlQuery query = db.exec("SELECT 1 FROM SYSIBM.SYSDUMMY1");
while (query.next() == true) {
qDebug() << query.value(0).toString();
}
Objavite komentar