• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Oracle - error - Not an instance of DirContext

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Trying to connect oracle through AEM 6.2 and I am facing this error,

Can somebody help me understand the below error   "Not an instance of DirContext", why this error is throw when trying to establish connection,



SQLException in getting connection java.sql.SQLRecoverableException: IO Error: JNDI Package failure javax.naming.NotContextException: Not an instance of DirContext,IO Error: JNDI Package failure javax.naming.NotContextException: Not an instance of DirContext

Thanks

Vetrik
 
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You will probably need to supply a lot more information to get any help.  TellTheDetails (that's a link).

First, copy and paste to entire error message, stack trace and all.  Then tell us what you were doing to get the error.
 
Vetrik Kumaran
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Trying to establish connection to oracle from a servlet (AEM 6.2) , AEM does provide  Data Source Pool service and Ia m trying to use that to get the connection  (Day Commons Library - JDBC pool provider for the Data Source Pool (day.commons.datasource.jdbcpool), Version 1.0.24)

I will paste the code below, and this is all the  error that I get in my error log.  I am trying to understand what is this DirContext

JDBC Connection URI :  jdbc:oracle:thin:@ldap://XXXXXXXXXXXX:3060/AEM_SVC1_L1;cn=OracleContext[/size]


Here is the full error ,

SQLException in getting connection java.sql.SQLRecoverableException: IO Error: JNDI Package failure javax.naming.NotContextException: Not an instance of DirContext, IO Error: JNDI Package failure javax.naming.NotContextException: Not an instance of DirContext

Please let me know if more details needed.



************* Connection Helper class *******************
ublic Connection getConnection(final String oracleDBConnection ) {
DataSource dataSource = null;
Connection connection = null;
try {
if (null != oracleDBConnection && !oracleDBConnection.isEmpty() && null!= dataSourcePool) {
dataSource = (DataSource) dataSourcePool.getDataSource(oracleDBConnection);
if (dataSource != null) {
connection = dataSource.getConnection();
}
}


************************  Test Servlet *************************************

@Component(label = "test connection", description = "test connection", metatype = true)
@Properties({
@Property(label = "Paths", description = "Servlet Paths.", name = "sling.servlet.paths", value = { "/services/testconnection" }, propertyPrivate = false),
@Property(name = "sling.servlet.methods", value = { "GET", "POST" }, propertyPrivate = true) })
@Service(Servlet.class)
public class TestServlet extends SlingAllMethodsServlet{

/**
*
*/
private static final long serialVersionUID = 1L;

/** The Constant LOG. */
private static final Logger log = LoggerFactory.getLogger(TestServlet.class);

private static final String ORACLE_DATA_SOURCE = "brand";

private static  String queryString ="select table_name from all_tables";
   
   /** The query builder. */
  @Reference
   private ConnectionHelper  connectionHelper;
 
  /** @scr.reference policy="static" */
  private DataSourcePool dataSourceService;
DataSource dataSource = null;
Connection connection = null;
@Override
protected void doGet(SlingHttpServletRequest request,
SlingHttpServletResponse response) throws ServletException,
IOException {
try {
log.info("DATA_SOURCE   -->"+ORACLE_DATA_SOURCE);
connection = connectionHelper.getConnection(ORACLE_DATA_SOURCE);
log.info("connection-->"+connection);

//dataSource = (DataSource) dataSourceService.getDataSource("brand");
final ResultSet resultSet = connection.createStatement().executeQuery(queryString);
log.info("ResultSet : " + resultSet);

} catch (Exception e) {
log.error("Exception from DOGET in test servelt {}", e.getStackTrace());
e.printStackTrace();
//e.getStackTrace();

} finally {
if(null!=connection){
try {
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}

}
}

}




 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure I'll be able to help you with the problem, but I will at least help you with how to post in a way that will get more help.

When you post code, please UseCodeTags (that's a link).  Basically, surround your code with code tags.

Use the Preview button, next to the Submit button, to see how your post will be rendered.

Post full stack traces.  That means everything displayed on your console or the relevant part of your log file.  A stack trace looks like this:
It usually has a lot more entries below the first line.  Notice that it has the exception, the class, and the line of the code (5 in this case).  Your post does have a class or line in it.  We need that.

Post full classes, or at least full methods if they're self-contained.  With code tags added, you posted this:
"public" was cut off; there is no catch for the try; there is no return statement; what is the variable dataSourcePool?  Do you get the point?

So now do this: find the stack trace; find the class and line number; post the full stack trace; post the full Java class.
 
Vetrik Kumaran
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Thanks Knute.

Here is stack trace and code










 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the complete information.  Let's take a look at it.  First the Stack Trace.  These can be intimidating, but you can learn to glean information from them.  First, scan down looking for your classes:
There they are.  So class TestServlet, method doGet(), line 72 invoked ConnectionHelper, getConnection() at line 42.  So let's look at line 42:
Oops.  This can't be the offending line.  So probably your listing does not exactly match what was executed.  The error might have occurred on line 41 or 39.  Let's keep going.
So TestServlet, in method doGet(), got a NPE at line 76.
Again, this can't be the line.  So the listing for TestServlet is also off.  Since we know the error happened in ConnectionHelper.getConnection(), we'll assume the line is really 68.

So post a stack trace and class listings that match exactly, blank lines and all.  I just use a Ctrl-A to copy everything (Windows).  But I suspect line 39 in ConnectionHelper.  You might want to log a message there with some of the used values.
 
reply
    Bookmark Topic Watch Topic
  • New Topic