| Author |
DriverManager.getConnection() not working in runtime but working fine in debug mode of Eclipse
|
Tarun Maheshwari
Greenhorn
Joined: Mar 08, 2010
Posts: 5
|
|
Hi all,
I'm facing a very strange problem. Dunno doing some silly mistake or what.
I have a Java application which connects to the database.
The code snippet is as follows:
"String theConnectionString = theDataSource.getConnectionString();
String theDriverName = theDataSource.getDriverName();
String theUserID = theDataSource.getUserID();
String thePassword = theDataSource.getPassword();
// Load the driver
Class.forName(theDriverName);
// Get the connection
m_Connection = DriverManager.getConnection(theConnectionString, theUserID, thePassword);
// Create statement
m_Statement = m_Connection.createStatement();
// Set to connected
m_Connected = true;
// log
INBULog.log("DB Connect to " + theConnectionString + " - OK");"
When I compile and run the above code in Eclipse, I get an exception:
Error occurred in INBUProcessor:doDBInitialization
java.sql.SQLException: [Microsoft][ODBC Driver Manager] Invalid string or buffer length
at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.SQLGetDataString(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcResultSet.getDataString(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcResultSet.getString(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcConnection.buildTypeInfo(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcConnection.initialize(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at com.aexp.inbu.common.INBUDB.connect(INBUDB.java:31)
at com.aexp.inbu.common.INBUProcessor.doDBInitialization(INBUProcessor.java:372)
at com.aexp.inbu.common.INBUProcessor.doInitialization(INBUProcessor.java:304)
at com.aefa.inbu.docserver.DocServerProcessor.doInitialization(DocServerProcessor.java:323)
at com.aexp.inbu.common.INBUProcessor.execute(INBUProcessor.java:186)
at com.aexp.inbu.common.INBUProcessor.run(INBUProcessor.java:163)
at java.lang.Thread.run(Unknown Source)"
Now,I tried to run the same code in debug mode in Eclipse and set the breakpoints at lines:
// Load the driver
[Breakpoint-1] Class.forName(theDriverName);
// Get the connection
[Breakpoint-2] m_Connection = DriverManager.getConnection(theConnectionString, theUserID, thePassword);
// Create statement
[Breakpoint-3] m_Statement = m_Connection.createStatement();
When I press F6 from [Breakpoint -2] to [Breakpoint -3], the code is executing fine and connection is getting established.
But When I press F8 from [Breakpoint -2] to [Breakpoint -3], the code is throwing the above mentioned exception.
The connection string is: "jdbc:odbc:IAD"
The System specifications are:
OS: Windows Server 2008 - Enterprise - 64 bit
Database: SQL Server 2005
Eclipse version: Eclipse Helios Release
I'm totally confused and have no clue as to what is happening.
Please help..!
|
 |
Paul Sturrock
Bartender
Joined: Apr 14, 2004
Posts: 10336
|
|
|
Why are you using the JDBC-ODBC bridge? SQL Server has its own type 4 drivers (both MS and third party). Unless you have to use it I'd avoid it.
|
JavaRanch FAQ HowToAskQuestionsOnJavaRanch
|
 |
Tarun Maheshwari
Greenhorn
Joined: Mar 08, 2010
Posts: 5
|
|
This is an existing application and we have to go ahead with the JdbcOdbc driver.
|
 |
Paul Sturrock
Bartender
Joined: Apr 14, 2004
Posts: 10336
|
|
OK. So long as its not in production that's OK (Oracle are pretty unequivocal on the use of that).
When I press F6 from [Breakpoint -2] to [Breakpoint -3], the code is executing fine and connection is getting established.
But When I press F8 from [Breakpoint -2] to [Breakpoint -3], the code is throwing the above mentioned exception.
Remind me, what do those keyboard short cuts do in Eclipse?
|
 |
Tarun Maheshwari
Greenhorn
Joined: Mar 08, 2010
Posts: 5
|
|
F6 will step over the call, e.g. it will call a method / function without entering the associated code.
F8 will go to the next breakpoint. If no further breakpoint is encountered then the program will normally run.
|
 |
Paul Sturrock
Bartender
Joined: Apr 14, 2004
Posts: 10336
|
|
|
Must be some defect or limitation of the JDBC-ODBC bridge. Not sure if there is anything you can do about it.
|
 |
Wendy Gibbons
Bartender
Joined: Oct 21, 2008
Posts: 1098
|
|
|
in my exeperince (general) if stuff works in debug but not other, something is being formated by the debug window, it could be your variables or theirs
|
 |
Tarun Maheshwari
Greenhorn
Joined: Mar 08, 2010
Posts: 5
|
|
Hi all,
I found the solution to my problem. There is a known issue in Windows 2008 Server for the JDBC-ODBC bridge Type 1 driver, so I switched to the SQL Server specific Type 4 driver and it is working.
Thanks all for your valuable suggestions.
|
 |
Anand Ra
Greenhorn
Joined: Aug 28, 2012
Posts: 1
|
|
I found the solution to my problem. There is a known issue in Windows 2008 Server for the JDBC-ODBC bridge Type 1 driver
Tarun, Do you have a web link mentioning the known issue, say a Microsoft bug report? I'm facing the same kind of issue with JRE 6 64-bit and on Windows 2008 64-bit computer. Yes the JTDS driver works great. I need more information to document this behavior while the JDBC-ODBC bridge. Thanks!
|
 |
pravin gajbhiye
Greenhorn
Joined: Aug 20, 2012
Posts: 20
|
|
Hey tarun
Iaam getting same problem with jdbc connection
java.sql.SQLException: [Microsoft][ODBC Driver Manager] Invalid string or buffer length
but its work in debug mode.
I have installed
Java6
MySQL Server 5.1
mysql-connector-java-5.1.22 to create datasourse Name.
System configuration
windows 7 win 64
please help me..
what kind of driver i have to installe. please give a link if you have.
|
 |
 |
|
|
subject: DriverManager.getConnection() not working in runtime but working fine in debug mode of Eclipse
|
|
|