I have a web project in eclipse using glassfish. I have the following datasource entries in context.xml
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<Resource name="jdbc/TestDS" type="javax.sql.DataSource"
url="jdbc:oracle:thin:@server:1521:db1"
driverClassName="oracle.jdbc.OracleDriver" username="test" password="test" />
</Context>
When I run my application
DatabaseMetaData dmd = connection.getMetaData();
String name = dmd.getDatabaseProductName();
Database product name is always Apache Derby
What could be the reason for this? I am trying to connect to Oracle Database however connection is made to Apache Derby.
How can I resolve this issue?
Thanks
Update 1
public static DatabaseConnection getInstance(String name)
throws DatabaseException {
DatabaseConnection instance;
DataSource ds;
try {
InitialContext ctx = new InitialContext();
ds = (DataSource) new InitialContext().lookup("java:comp/env/"
+ name);
} catch (NamingException e) {
e.printStackTrace();
throw new DatabaseException("###data source is invalid ###" + e);
}
instance = new MYDataSource(ds);
return instance;
}
I have resolved this issue.
I created a a JDBC Resource under GlassFish and pointed connection to my connection created under Date Source Explorer. It created a
sun-resources.xml. I had to manually rename this toglassfish-resource.xml. By default there are no entry for password,so I had to manually add<property name="Passwrod" value="password" />. When I ran my web application I was getting this errorSo to resolve this error I added a property in JDBC Connection Pool in glassfish admin server. Now I could connect to Oracle database.
Not sure why I have to do two steps manually.
Thanks