This discussion is archived
4 Replies Latest reply: Nov 28, 2012 10:47 AM by 976571 RSS

JDBC-ODBC and JNDI issue

976571 Newbie
Currently Being Moderated
I have a table (called tabla) in a database (Access). I have created a System DSN (ODBC) for that database (called Prueba). When I try to get to the data with this code y get the subsecuent exception (when I go through the connection, statement, etc. everything works fine).
Code:
...
String name = "jdbc:odbc:Prueba";
FilteredRowSet retVal= new FilteredRowSetImpl();
retVal.setDataSourceName( name);
retVal.setCommand( "Select * from tabla");
retVal.execute();
...
Exception:
Exception in thread "main" java.sql.SQLException: (JNDI) No se puede conectar
     at com.sun.rowset.internal.CachedRowSetReader.connect(CachedRowSetReader.java:317)
     at com.sun.rowset.internal.CachedRowSetReader.readData(CachedRowSetReader.java:140)
     at com.sun.rowset.CachedRowSetImpl.execute(CachedRowSetImpl.java:786)
     at com.sun.rowset.CachedRowSetImpl.execute(CachedRowSetImpl.java:1418)
     at abc.Modelo.getRowSet(Modelo.java:77)
     at abc.Modelo.<init>(Modelo.java:32)
     at abc.ABC.inicializa(ABC.java:90)
     at abc.ABC.<init>(ABC.java:35)
     at abc.Main.main(Main.java:18)
Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
     at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
     at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
     at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)
     at javax.naming.InitialContext.lookup(InitialContext.java:392)
     at com.sun.rowset.internal.CachedRowSetReader.connect(CachedRowSetReader.java:301)
     ... 8 more
Please, Can anyone tell me how can I fix this code and make it work?
Any help is welcome.
Thanks in advance.
  • 1. Re: JDBC-ODBC and JNDI issue
    jschellSomeoneStoleMyAlias Expert
    Currently Being Moderated
    javax.naming.NoInitialContextException:
    You must set up the JNDI context. And it appears you dd that wrong.

    You can google for examples on how to do that.
  • 2. Re: JDBC-ODBC and JNDI issue
    976571 Newbie
    Currently Being Moderated
    Can anyone be more explicit?
    Please, even in a sketchy way, indicate what is required "to set up the jndi context".
    Any help would be appreciated.
    Thanks in advance.
  • 3. Re: JDBC-ODBC and JNDI issue
    EJP Guru
    Currently Being Moderated
    What part of
    Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
    don't you understand? It is one of the most explicit and complete error messages I have ever seen in 40+ years of computer programming.

    Have you considered reading the documentation?

    Have you noticed that the exception isn't thrown by the code you posted?
  • 4. Re: JDBC-ODBC and JNDI issue
    976571 Newbie
    Currently Being Moderated
    Ok. Lets assume I choose application resource file. I do believe that I have to put a line like "java.naming.factory.initial=<something>". The question is now: what is the right <something>? (Given that I want to access a DSN created for ODBC).
    One more question: is that all, or I am required to do something else? (Like independently "register" a datasource for jndi and something else).
    Thank you very much in advance.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points