We help IT Professionals succeed at work.

Trying to make an ODBC connection but no ResultSet gets returned!

snajalm asked
I'm trying to make an jdbc-odbc connection like the following.  I get connected but my resultset does not get populated.  What do you think the problem could be.  Here's my code,

String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
String url = "jdbc:odbc:" + address + ";user=" + username + ";password=" + password;

PreparedStatement pStmt = conn.prepareStatement(query);
ResultSet rs = pStmt.executeQuery();
Watch Question

Awarded 2011
Awarded 2011

What is your query ?


It is a very long query and I can't post it on here due to security reasons!  But do you have any idea of what the situation may be that the server would not return the requested ResultSet despite the fact that the connection is in fact successfully made?!
Awarded 2011
Awarded 2011

Maybe query returns nothing?

Does this quesry have no parameters?
If so, why do yiou need to have peraperdStatement?

Try to see what happens with conventional Statement
I'm also usualy claling Class.forName() before Driver.getConnection() though it is probably not important
Top Expert 2016
Try the exact same query outside java


There is nothing wrong with the query since it has been used from other applications and is valid in terms of execution and providing a valid result!
Awarded 2011
Awarded 2011
How do you know that it generates no results?

Show more of your code.

Try to use another query selecting everything form the table
and insert System.out.println(..) within the loop

Then you'll have at least some information.

Otherwise, one can think anything - maybe you hitting different database.
Maybe there is some error in sql.

Just follow your code and insert System.out.println(..)
just before reading ResultSet, within the reading loop, just outside the loop.
If you see before and outside and don't see anything from within
then try to put another query.

Make sure that you don't have any exceptions which are caught but not reported by printStackTrace()
or other printouts.
Usually do something, chnage some coniditions and try.
There may be sometimes a misprint which you'll not notice staring at the code
When you do some modifiction you end up
being confronted with the error.

Otherwise it is impossible to know what is ghoing on without much data, like in yiour case.


Well, it ended up to be a silly mistake from my side where I was passing the wrong arguments!

Explore More ContentExplore courses, solutions, and other research materials related to this topic.