This week's book giveaway is in the Testing forum.
We're giving away four copies of Data Structures the Fun Way: An Amusing Adventure with Coffee-Filled Examples and have Jeremy Kubica on-line!
See this thread for details.
  • 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
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

servlet onstart up can't find db resource reference name

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This servlet works if I start it manually after the server has stated but not with a scheduler in the servlet. The schduler starts the job. but the job fails with this error.

[6/20/08 15:17:06:016 EDT] 0000002a SystemErr R com.ibm.db.beans.DBException: Unexpected error; javax.naming.NameNotFoundException: Name "comp/env/espConn" not found in context "java:".
at com.ibm.db.beans.DBException.getSQLException(DBException.java)
at com.ibm.db.beans.DBSelect.execute(DBSelect.java)
at net.ongov.esp.resources.ExamPostedTodayByJobtitle.execute(ExamPostedTodayByJobtitle.java:45)
at net.ongov.esp.resources.ScheduledExamNotification.scheduleJob(ScheduledExamNotification.java:104)
at net.ongov.esp.resources.ScheduledExamNotification$1.run(ScheduledExamNotification.java:308)
at java.util.TimerThread.mainLoop(Timer.java:447)
at java.util.TimerThread.run(Timer.java:397)

Why can't the job find the db resource reference name when it starts on it's own?
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
may be the scheduler in a different context
 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Denise Smith:
This servlet works if I start it manually after the server has stated but not with a scheduler in the servlet. The schduler starts the job. but the job fails with this error.

[6/20/08 15:17:06:016 EDT] 0000002a SystemErr R com.ibm.db.beans.DBException: Unexpected error; javax.naming.NameNotFoundException: Name "comp/env/espConn" not found in context "java:".
at com.ibm.db.beans.DBException.getSQLException(DBException.java)
at com.ibm.db.beans.DBSelect.execute(DBSelect.java)
at net.ongov.esp.resources.ExamPostedTodayByJobtitle.execute(ExamPostedTodayByJobtitle.java:45)
at net.ongov.esp.resources.ScheduledExamNotification.scheduleJob(ScheduledExamNotification.java:104)
at net.ongov.esp.resources.ScheduledExamNotification$1.run(ScheduledExamNotification.java:308)
at java.util.TimerThread.mainLoop(Timer.java:447)
at java.util.TimerThread.run(Timer.java:397)

Why can't the job find the db resource reference name when it starts on it's own?



Perhaps the name is not yet bound by the time the scheduler starts ? Exactly when does the name get bound in the JNDI ? What server is this and what scheduler is it ?
 
Denise Smith
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Murthy Tanniru:
may be the scheduler in a different context



I think Murthy may be correct I spawned a new thread in the init() method of a load on start up servlet. That thread is outside the current context.
 
Deepak Bala
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Denise Smith:


I think Murthy may be correct I spawned a new thread in the init() method of a load on start up servlet. That thread is outside the current context.



I am not sure I follow. You have 2 JNDI contexts ? If the scheduler has access to the same JNDI that the name is bound to, there should be no problem accessing the bound object
 
Denise Smith
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by John Meyers:


I am not sure I follow. You have 2 JNDI contexts ? If the scheduler has access to the same JNDI that the name is bound to, there should be no problem accessing the bound object



actually...the thread code doesn't know the context information and I don't know how to tell it.
when I setDataSourcename this is the error I get

select.setDataSourceName((String)new InitialContext().lookup("java:comp/env/espConn"));

[6/23/08 12:10:40:562 EDT] 0000003c SystemErr R javax.naming.NameNotFoundException: Name "comp/env/espConn" not found in context "java:".
at com.ibm.ws.naming.ipbase.NameSpace.lookupInternal(NameSpace.java:1094)
at com.ibm.ws.naming.ipbase.NameSpace.lookup(NameSpace.java:990)
at com.ibm.ws.naming.urlbase.UrlContextImpl.lookup(UrlContextImpl.java:1263)
at com.ibm.ws.naming.java.javaURLContextRoot.lookup(javaURLContextRoot.java:201)
at com.ibm.ws.naming.java.javaURLContextRoot.lookup(javaURLContextRoot.java:142)
at javax.naming.InitialContext.lookup(InitialContext.java:361)
at net.ongov.esp.resources.LocalExamSeriesForExamPostedToday.initializer(LocalExamSeriesForExamPostedToday.java:44)
at net.ongov.esp.resources.LocalExamSeriesForExamPostedToday.<init>(LocalExamSeriesForExamPostedToday.java:27)
at net.ongov.esp.resources.ScheduledExamNotification.scheduleJob(ScheduledExamNotification.java:100)
at net.ongov.esp.resources.ScheduledExamNotification$1.run(ScheduledExamNotification.java:316)
at java.util.TimerThread.mainLoop(Timer.java:447)
at java.util.TimerThread.run(Timer.java:397)


Any suggestions? how can I get the context that the servlet is using
 
Deepak Bala
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I am not mistaken, you are trying to access a bound datasource in the JNDI on application startup ? Why not do that in a servlet context listener ? That may be a better place to put the code and schedule whatever you want to. If this is supposed to run like a batch, you should ask yourself if it belongs in a web application.

If you have a JNDI explorer you can also see if the name is actually bound when you are looking for it.
 
Denise Smith
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is my init method of the servlet: this executes the class ReadMail and the method scheduleJob();

*/
public void init(ServletConfig arg0) throws ServletException {
// TODO Auto-generated method stub

//Use the schedule() method of the java.util.Timer class:
ServletContext sc = arg0.getServletContext();


System.out.println("Initializing Scheduler for Notifications");
long now = System.currentTimeMillis();
long millisecondsInFuture = 30000 ;
Date whenToRun = new Date(now + millisecondsInFuture);
Timer timer = new Timer();
TimerTask task = new TimerTask() {
public void run() {
// job code here
String[] args = {};
try {
ReadMail.main(args);
scheduleJob();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}


}
};
timer.schedule(task, whenToRun);
}


ReadMail workds great(there are no data access beans in this class)
the scheduleJob(); starts to run but as soon as it hits tries to get the datasource it errors with the error provided previously.

here is the the Try block that cathes the Naming exception:

try {

select.setDataSourceName((String)new InitialContext().lookup("java:comp/env/espConn"));

select.setCommand("some select statement");
DBParameterMetaData parmMetaData = ParameterMetaData();
parmMetaData.setParameter(1, "somevariable",
java.sql.DatabaseMetaData.procedureColumnIn,
java.sql.Types.CHAR, String.class);
}


can anyone help me???

If I run my code without spawning a new thread it works
 
look! it's a bird! it's a plane! It's .... a teeny tiny ad
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic