35

I need to handle resultsets returning stored procedures/functions for three databases (Oracle, sybase, MS-Server). The procedures/functions are generally the same but the call is a little different in Oracle.

statement.registerOutParameter(1, oracle.jdbc.OracleTypes.CURSOR);
...
statement.execute(); 
ResultSet rs = (ResultSet)statement.getObject(1);

JDBC doesn't provide a generic way to handle this, so I'll need to distinguish the different types of DBs in my code. I'm given the connection but don't know the best way to determine if the DB is oracle. I can use the driver name but would rather find a cleaner way.

tshepang
  • 12,111
  • 21
  • 91
  • 136

2 Answers2

56

I suspect you would want to use the DatabaseMetaData class. Most likely DatabaseMetaData.getDatabaseProductName would be sufficient, though you may also want to use the getDatabaseProductVersion method if you have code that depends on the particular version of the particular database you're working with.

Jerven
  • 582
  • 3
  • 7
Justin Cave
  • 227,342
  • 24
  • 367
  • 384
3

You can use org.apache.ddlutils, class Platformutils:

databaseName = new PlatformUtils().determineDatabaseType(dataSource)
Andrew Swan
  • 13,427
  • 22
  • 69
  • 98
Rinat Tainov
  • 1,479
  • 2
  • 19
  • 39