tags:

views:

725

answers:

4

Hi,

How I could determine if JDBC driver is TYPE_FORWARD_ONLY? In my program the user configures connection parameters to database and he could use any JDBC driver in the class path. I want to know if the driver is TYPE_FORWARD_ONLY before executing any statements. Is this possible?

A: 

There are Drivers that don't support scrolling? Could you give an example? What does such a driver return, when you try to create a Statement/ResultSet that is SCROLL_SENSITIVE and then ask for the Type? Like this:

Connection con = ...;
Statement statement = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ...);
System.out.println(statement.getResultSetType());
Tim Büthe
here's a discussion of one that I came across : http://osdir.com/ml/db.sqlite.jdbc/2008-05/msg00048.html
Steve B.
A: 

You can get DriverPropertyInfo from the driver, although I can't find a specific jdbc specification that describes what the driver must return. This reference may have more.

Steve B.
+1  A: 

By querying the type of result set. For example:

Statement stmt = con.createStatement(
 ResultSet.TYPE_FORWARD_ONLY,
 ResultSet.CONCUR_UPDATABLE
);
ResultSet rs = stmt.executeQuery("SELECT a, b FROM TABLE2");
System.out.println(
 "Is Type Forward Only: " + 
 (rs.getType() == ResultSet.TYPE_FORWARD_ONLY)
);
Boris Pavlović
Would this not throw a SQLFeatureNotSupportedException if the ResultSet did not support TYPE_FORWARD_ONLY?
Mark
+3  A: 

DatabaseMetaData has a method supportsResultSetType(int type) that you could use to check if the ResultSet supports TYPE_FORWARD_ONLY.

Mark