Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

DriverManager.getConnection() not working in runtime but working fine in debug mode of Eclipse

 
Tarun Maheshwari
Greenhorn
Posts: 5
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Tarun Maheshwari
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is an existing application and we have to go ahead with the JdbcOdbc driver.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1110
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic