3

In jdbc, how to check, that we are using oracle 8i database?

sidslog
  • 654
  • 1
  • 6
  • 15

3 Answers3

6
Connection connection = DriverManager.getConnection(url);
DatabaseMetaData meta = connection.getMetaData();
String product = meta.getDatabaseProductName();
String major = meta.getDatabaseMajorVersion();
String minor = meta.getDatabaseMinorVersion();
duffymo
  • 305,152
  • 44
  • 369
  • 561
  • Thanks @duffymo, i have another questin. Will meta.getDatabaseProductName().contains("8i") be enough to check that we're using oracle 8i? Can oracle driver return another string? Or can another oracle driver used with another oracle db return string that contains "8i"? – sidslog May 23 '11 at 16:59
  • I don't know. I don't have multiple instances of Oracle available to me to try it. If you do, I'd recommend writing a small Java class with a main method containing the lines that I gave you and try it out with different connection URLs. Be an experimentalist. – duffymo May 23 '11 at 19:55
5

You might have to use the Database metadata class.

Buhake Sindi
  • 87,898
  • 29
  • 167
  • 228
Jai
  • 3,549
  • 3
  • 23
  • 31
2

Run:

select * from v$version

It should produce something like:

Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
PL/SQL Release 10.2.0.4.0 - Production
...

Then it's just a simple matter of parsing that 1st result row.

Tom Tresansky
  • 19,364
  • 17
  • 93
  • 129
  • Unfortunately, that only works for an Oracle database. The JDBC DatabaseMetaData approach works for a variety of databases. – Stephen C May 23 '11 at 12:46
  • @Stephen C: The DatabaseMetaData approach does seem to be a better solution, and it has my upvote; however, the question was specifically about an Oracle db...I had assumed the OP knew he was using Oracle, and just wanted to find out the version. – Tom Tresansky May 23 '11 at 12:55