on 05-03-2005 7:05 PM
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
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
88 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.