I am about to be crazy for this problem for 2 days. I have an application which has one client project(UI), an application server, one client project( makes some computations using another program).Clients and server communicate with each other using jms. I am trying to connect access database from computation client, Application hangs on while executing following statement of DriverManager class
di.driver.connect(url, info);
I am able to connect from server, also UI client with the same code. My system is not distributed .All Projects are reside in my local environment. So their operating environment same. They use same jdk. Please tel me what can be the problem
I call following function before getting connection.It creates odbc data source.
public static void createODBCSource(String dbPath) {
// ODBC parameters
String[] argsXP = { "ODBCCONF", "CONFIGDSN",
"Microsoft Access Driver (*.mdb)",
"DSN=datasource-db;Server=localhost;Port=3306;DBQ=" + dbPath };
String[] argsVistaSeven = { "C:\\Windows\\SysWOW64\\odbcconf.exe",
"CONFIGDSN", "Microsoft Access Driver (*.mdb)",
"DSN=psa-db;Server=localhost;Port=3306;DBQ=" + dbPath };
// creating a process for the ODBC
ProcessBuilder pb = null;
String version = System.getProperty("os.name");
if (version.equals("Windows XP")) {
pb = new ProcessBuilder(argsXP);
} else if (version.equals("Windows 7")
|| version.equals("Windows Vista")) {
pb = new ProcessBuilder(argsVistaSeven);
}
// starting the process
pb.directory(new File("."));
try {
Process p = pb.start();
p.getInputStream().close();
p.getOutputStream().close();
p.getErrorStream().close();
try {
p.waitFor();
} catch (InterruptedException ex) {
ex.printStackTrace();
return;
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
Then I call following function to get connection
private static final String URL_MS_ACCESS = "jdbc:odbc: datasource-db ";
public static Connection connect(String user, String pass, int db) throws SQLException {
Connection conn = null;
if (db == MYSQL) {
try {
Class.forName(DRIVER_MYSQL);
} catch (ClassNotFoundException ex) {
Logger.getLogger(DatabaseConnector.class.getName()).log(Level.SEVERE, null, ex);
}
conn = DriverManager.getConnection(URL_MYSQL, user, pass);
} else if(db == ACCESS) {
try {
Class.forName(DRIVER_MS_ACCESS);
} catch (ClassNotFoundException ex) {
Logger.getLogger(DatabaseConnector.class.getName()).log(Level.SEVERE, null, ex);
}
conn = DriverManager.getConnection(URL_MS_ACCESS, "", "");
}
return conn;
}
EDIT
Computation Client works by listening jms messages(Implements MessageListener).It does jobs when it receive a jms message from server(onMessage method). Getting access connection does not work after this point. I do not know how it is logic.I think that is is thread related.
I set log writer of DriverManager to debugging. This is the log written. It hangs SQLAllocConnect. Please show me a way to handle.
JdbcOdbcDriver class loaded
registerDriver: driver[className=com.mysql.jdbc.Driver,com.mysql.jdbc.Driver@1e88b35]
DriverManager.initialize: jdbc.drivers = null
JDBC DriverManager initialized
registerDriver: driver[className=sun.jdbc.odbc.JdbcOdbcDriver,sun.jdbc.odbc.JdbcOdbcDriver@b655a]
DriverManager.getConnection("jdbc:odbc:romania-db")
trying driver[className=com.mysql.jdbc.Driver,com.mysql.jdbc.Driver@1e88b35]
trying driver[className=sun.jdbc.odbc.JdbcOdbcDriver,sun.jdbc.odbc.JdbcOdbcDriver@b655a]
*Driver.connect (jdbc:odbc:datasource-db)
JDBC to ODBC Bridge: Checking security
No SecurityManager present, assuming trusted application/applet
JDBC to ODBC Bridge 2.0001
Current Date/Time: Fri Jan 18 17:25:53 EET 2013
Loading JdbcOdbc library
Allocating Environment handle (SQLAllocEnv)
hEnv=404691320
Allocating Connection handle (SQLAllocConnect)
hDbc=404691488
Connecting (SQLDriverConnect), hDbc=404691488, szConnStrIn=DSN=datasource-db
I thing Joop advice to first try to use manually created DSN is good. While you use JDBC-ODBC bridge you can monitor ODBC calls via Trace feature than can be enabled from ODBC Manager. This is part of my trace sql.log
when I connected from Jython to Access using jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=c:\\\\Nwind.mdb
:
*" org.python.u 83c-928 ENTER SQLAllocEnv
HENV * 00A6F3F0
*" org.python.u 83c-928 EXIT SQLAllocEnv with return code 0 (SQL_SUCCESS)
HENV * 0x00A6F3F0 ( 0x044a1c18)
*" org.python.u 83c-928 ENTER SQLAllocConnect
HENV 044A1C18
HDBC * 00A6F350
*" org.python.u 83c-928 EXIT SQLAllocConnect with return code 0 (SQL_SUCCESS)
HENV 044A1C18
HDBC * 0x00A6F350 ( 0x044a1cc0)
*" org.python.u 83c-928 ENTER SQLDriverConnectW
HDBC 044A1CC0
HWND 00000000
WCHAR * 0x74609110 [ -3] "******\ 0"
SWORD -3
WCHAR * 0x74609110
SWORD 2
SWORD * 0x00000000
UWORD 0 <SQL_DRIVER_NOPROMPT>
*" org.python.u 83c-928 EXIT SQLDriverConnectW with return code 0 (SQL_SUCCESS)
HDBC 044A1CC0
HWND 00000000
WCHAR * 0x74609110 [ -3] "******\ 0"
SWORD -3
WCHAR * 0x74609110
SWORD 2
SWORD * 0x00000000
UWORD 0 <SQL_DRIVER_NOPROMPT>
...
As you see there is ENTER
, EXIT
pair of each API call so it would be easy to see which API function hung.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.