[Qt-jambi-interest] Qt-Jambi and MySQL access
Petric Frank
pfrank at gmx.de
Wed Aug 12 13:20:10 CEST 2009
Hello,
On Dienstag, 11. August 2009, Eskil Abrahamsen Blomfeldt wrote:
> Sorry, this was my mistake. I was thinking of an earlier instance of the
> API. The correct way to initialize QJdbc is the following:
>
> QJdbc.initialize();
>
> Replace the reference to QJdbcSqlDriver with this, and the code should
> hopefully work.
I was looking to get an SSL enabled DB connection because a cleartext DB
connection via internet and/or intranet is (in my opinion) not a good idea.
I tried to use
db.setDatabaseName("jdbc:mysql://hostname/db?useSSL=true");
but this doesn't work. After digging a bit inside the source code of
DriverManager and QJdbcSqlDriver i think i know why.
Could i propose a change to com.trolltech.qt.sql.QJdbcSqlDriver like this
(partially taken from Qt/C++ MySQL driver, untested, but to get the idea):
------------------------------- cut -----------------------------
....
public boolean open(String db,
String user,
String password,
String host,
int port,
String connOpts)
{
Connection con = null;
try {
java.util.Properties info = new java.util.Properties();
if (user != null)
info.put("user", user);
if (password != null)
info.put("password", password);
// some code splitting the connOpts parameter and put them to <info>
String[] opts = connOpts.split (";");
for (String opt : opts) {
// here you may have to split parameters by equal sign
if (opt == "CLIENT_SSL")
info.put("useSSL", "true");
...
}
con = DriverManager.getConnection(db, info);
} catch (SQLException ex) {
....
------------------------------- cut -----------------------------
On this way you may pass additional options to low level database drivers
(like MySQl Connect/J).
Could that be an enhancement to be added to the next release ?
regards
Petric
More information about the Qt-jambi-interest
mailing list