cancel
Showing results for 
Search instead for 
Did you mean: 

How to discover the database vendor Name of the default connection

Former Member
0 Kudos

Im getting a db connection via context.lookup() to the default schema (SAPDB) and I want to discover the J2EE database vendor Name.

can anyone help me?

Regards

Armando

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Armando,

The following code will get you the vendor name.

Properties p = new Properties();
p.put("java.naming.factory.initial", "com.inqmy.services.jndi.InitialContextFactoryImpl");
        try
        {
            Context ctx = new InitialContext(p);
            ds = (DataSource)ctx.lookup("jdbc/sapep");
            Connection conn = _ds.getConnection();
          <b>  dbName = conn.getMetaData().getDatabaseProductName();</b>
           conn.close();
        }
        catch(NamingException ex)
        {
         }

PS: Please reward points if the answer resolves your problem.

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Prakash:

I have just installed a new WAS for MSSQL and your code runs fine, thks for the advise, the only think that I need is to know the other values that the function getDatabaseProductName() return, for Oracle, informix, etc.

Best Regards

Armando Alonso

Former Member
0 Kudos

Hi Armando,

I think for Oracle it just returns "Oracle". I am not too sure about the others. I would write a quick little program that connects to all this databases and dumps there product name.

Prakash Singh

Former Member
0 Kudos

Hi Prakash:

I tried that code and I get "SAP DB", but if I change the method using JDBC (not JNDI) with SQL server JDBC driver, I get null for getDatabaseProductName() method, I don´t now if using JNDI would be different since i don´t have any Web AS Java installed for SQL Server.

I have this Code:

Properties prop = System.getProperties();

Context context = new InitialContext();

DataSource ds;

Connection con;

String sysname = prop.getProperty("SAPSYSTEMNAME");

String DataSourceName = "jdbc/SAP" + sysname + "DB";

String dummyNull = "";

try {

ds = (DataSource) context.lookup(DataSourceName);

}

catch (Exception e) {

throw new HibernateException( "Could not find datasource", e );

}

con = ds.getConnection();

And When I inspect in debug Mode the con object

I get this:

"con"= CommonConnectionHandle (id=279)

___[...]

___mc= CommonManagedConnectionImpl (id=295)

______[...]

______con= CommonConnectionImpl (id=286)

_________[...]

_________connectionContext= CommonContextFactory$CommonConnectionContextImpl (id=333)

____________[...]

____________dataSourceContext= ContextFactory$DataSourceContextImpl (id=356)

_______________databaseName= "C14"

_______________dataSourceName= "SAPC14DB"

_______________serverName= "ARMANDOALONSO.neoris.cxnetworks."

_______________sqlType= 1

_______________userName= null

_______________vendorID= 6

_______________vendorName= "SAPDB"

____________[...]

____________userName= "SAPC14DB"

the data that I want to access is (vendorName= "SAPDB")

and I dont know how to do that.