Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Other SQL Server 2008 Topics
 prob while getting the version number of database

Author  Topic 

uday_gudurumca
Starting Member

1 Post

Posted - 2010-11-16 : 08:13:23
hi all,
I am using SQL Server 2008.
using "net.avenir.jdbc2.Driver" in caveconn25c.jar i have written a java class which connects to the database and prints the version number of the database product.

see the below code----

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
public class TestDBConnection{
public static void main(String[] args) {
Connection conn = null;
DatabaseMetaData metaData = null;
String url = "jdbc:AvenirDriver://INHYWVHMUPTST1:1433/";
String dbName = "hmdev";
String driver = "net.avenir.jdbc2.Driver";
String userName = "aditya";
String password = "aditya";

try {
Class.forName(driver).newInstance();
conn = DriverManager.getConnection(url+dbName,userName,password);
metaData = conn.getMetaData();
System.out.println("Archive Database Type: " + metaData.getDatabaseProductName());
System.out.println( "Archive Database Product Version: " + metaData.getDatabaseProductVersion());
conn.close();
System.out.println("Disconnected from database");
} catch (Exception e) {
e.printStackTrace();
}}}

but i am getting below exception---

Archive Database Type: Microsoft SQL Server 2008 R2 (RTM)
java.lang.StringIndexOutOfBoundsException: String index out of range: -7
at java.lang.String.substring(Unknown Source)
at net.avenir.jdbc2.q.getDatabaseProductVersion(DatabaseMetaData.java)
at TestDBConnection.main(TestDBConnection.java:22)

where as the same program is giving correct results, if i use SQL server 2005.

can anyone help me to findout whether the problem is with the Driver or anything else?

Thanks,
Uday
   

- Advertisement -