PDA

View Full Version : Accessing MySQL DB from application fired from Java application



redBeard
14th July 2011, 23:18
I have a Qt 4.7.0-based application working on both Linux (FC 13) n Windows Vista accessing a MySQL database. The Qt application connects to a MySQL database and reads some data. Everything works well when I fire the Qt application from my development IDE or installation structure on both Linux and Windows Vista.

However, in production I will be starting my Qt application from a Java (Eclipse RCP)-based application. The Java app fires the Qt app in a separate (Java application) thread as users can continue to use both applications at the same time.


Runtime rt = Runtime.getRuntime();
Process proc = rt.exec(cmdList.toArray(new String[]{}),envList.toArray(new String[]{}));


This all works well when everything is running on Linux. However, when I start the Qt application from the Java application on Windows Vista, I get the following error:


Can't create TCP/IP socket (10106) QMYSQL: Unable to connect

I don't understand why starting the Qt app from within the Java app would cause a problem....

According to the MSDN doc, error 10106 is:


WSAEPROVIDERFAILEDINIT - Service provider failed to initialize.

The requested service provider could not be loaded or initialized. This error is returned if either a
service provider's DLL could not be loaded (LoadLibrary failed) or the provider's WSPStartup or
NSPStartup function failed.

Yes, I call WSAStartup() before I open the database...

Ideas?

ChrisW67
15th July 2011, 01:02
The environment that your Java application is providing to the Qt app probably does not include one or more DLLs necessary to connect to the MySql database. They should be in the PATH or current working directory (make sure this is what you think it is). Given the error message I would assume that it is the MySQL lib that is not being found rather than the Qt Mysql plugin.

redBeard
15th July 2011, 21:48
I think you're correct with the fact that the application is not finding some DLL when launched from Java. I do have the MySQL library directory in the PATH (C:\Programs\MySQL\MySQLServer5.1\lib\opt) as well as the Qt plugins directory (C:\Programs\Qt\4.7.0\plugins\sqldriver) so I don't think those are the missing DLLs.

I'm running the application using Depends (as described in http://msdn.microsoft.com/en-us/library/ms235265%28v=VS.90%29.aspx). A little hokey to run, but....

The application is now failing with an access violation in MSVCR90D.DLL. MSVCR90D is indeed loaded. I scanned the Depends output and found the load of that library.

The end of the run (in Depends) says:



LoadLibraryW("uxtheme") called from "QTCORED4.DLL" at address 0x671AB7A3.
LoadLibraryW("uxtheme") returned 0x750D0000.
GetProcAddress(0x750D0000 [UXTHEME.DLL], "EndPanningFeedback") called from "QTCORED4.DLL" at address 0x671ABD78 and returned NULL. Error: The specified procedure could not be found (127).
LoadLibraryW("user32") called from "QTCORED4.DLL" at address 0x671AB7A3.
LoadLibraryW("user32") returned 0x767D0000.
GetProcAddress(0x767D0000 [USER32.DLL], "RegisterTouchWindow") called from "QTCORED4.DLL" at address 0x671ABD78 and returned NULL. Error: The specified procedure could not be found (127).
GetProcAddress(0x767D0000 [USER32.DLL], "GetTouchInputInfo") called from "QTCORED4.DLL" at address 0x671ABD78 and returned NULL. Error: The specified procedure could not be found (127).
GetProcAddress(0x767D0000 [USER32.DLL], "CloseTouchInputHandle") called from "QTCORED4.DLL" at address 0x671ABD78 and returned NULL. Error: The specified procedure could not be found (127).
Second chance exception 0xC0000005 (Access Violation) occurred in "MSVCR90D.DLL" at address 0x6378F8BC.
Exited "TRAINERTOOL.EXE" (process 0x43C) with code -1073741819 (0xC0000005).


There's 11 'GetProcAddress()' failures at the end of the run. I just showed 4 above.

Also, Depends complains that 'wintab32.dll' is missing. I'm not sure I need that, do I?!?

Also, also, I ran 'dumpbin /dependents' on my application using the same PATH as I used when I ran it with Depends and it responded with:



Dump of file trainerTool.exe

File Type: EXECUTABLE IMAGE

Image has the following dependencies:

log4cxx.dll
model.dll
flowEngine.dll
QtGuid4.dll
QtCored4.dll
MSVCP90D.dll
MSVCR90D.dll
KERNEL32.dll

Summary

2000 .data
11000 .idata
20000 .rdata
1000 .rsrc
46000 .text

I checked and all of the referenced DLLs above are loaded (when using Depends).

Still searching....

redBeard
28th October 2011, 23:24
Well, I reeeeeeally had to resolve this issue and I figgered it out....

The Qt MySQL layer uses the MySQL 'client' layer which tries to create a socket to the server. This socket() call was failing with the 10106 error code.

Turns out the Windblows socket library requires the SYSTEMROOT environment variable to be set in order to work. When I was launching the Qt-based application from Java, I was not setting that variable, I wanted to just set what I thought I needed - didn't think I needed that one...

This variable is normally set in cmd shells to C:\Windows. I just didn't set it in my Java ProcessBuilder variable map.

Problem solved.