[Qt-jambi-interest] Qt-Jambi and MySQL access
Eskil Abrahamsen Blomfeldt
eblomfel at trolltech.com
Tue Aug 11 10:21:54 CEST 2009
Petric Frank wrote:
> So i tried to do this here also. But after hours digging around i haven't
> found a guide how to do that.
>
> Could someone point me to some guide or hints to accomplish this ?
>
> As far as i know (i'm more a beginner in Java programming) jdbc may also be
> used to access MySQL. How the code above have to be rewritten.
> Probably someone have already written a jdbc(-mysql) driver for Qt-Jambi ...
>
Hi,
Qt Jambi comes with an undocumented JDBC driver. It will be documented
in the next release. Meanwhile, this is how you would use it with MySQL:
QJdbcSqlDriver.initialize();
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
} catch (Exception ex) { System.err.println(ex); return; }
QSqlDatabase db = QSqlDatabase.addDatabase("QJDBC");
db.setDatabaseName("jdbc:mysql://myhostname/mydatabase");
db.setUserName("myusername");
db.setPassword("mypassword");
if (db.open()) {
System.out.println("Connected!");
} else {
System.out.println("Connection Failed!");
System.out.println(db.lastError().text());
return;
}
From this point on, use Qt's SQL-classes as normal.
-- Eskil
More information about the Qt-jambi-interest
mailing list