1. View -> Database Navigator
2. Drag the IDE connection you wish to use in your workspace. The end result is as follows for the Workspace "WebLogicStuff"
3. Now whenever you run any web project from WebLogicStuff workspace then the database connection "scott" will automatically be deployed as an application level data source.
4. In order to access the connection "scott" we should use a JNDI location as follows within our code.
java:comp/env/jdbc/scottDS
The format would be as follows, depending on the connection name.java:comp/env/jdbc/{jdevide-connection-name}DS
Here is some java code we can then use to perform a JNDI lookup of the data source via a simple method which requires the location above to be passed to the method.
private Connection getConnection (String dataSourceLocation)
throws NamingException, SQLException
{
Connection conn = null;
// Get a context for the JNDI look up
Context ctx = new InitialContext();
// Look up a data source
javax.sql.DataSource ds
= (javax.sql.DataSource) ctx.lookup (dataSourceLocation);
// Create a connection object
conn = ds.getConnection();
return conn;
}
No comments:
Post a Comment