JNDI and Java Thread

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kokababu
    New Member
    • Jul 2008
    • 39

    JNDI and Java Thread

    Hi

    I am developing a WebService using Java (JAX-RPC).
    According to the requirement, I have to create a Thread to
    insert data into Database.

    So I am opening a database connection in the following way:
    Note: I am using runnable interface and I am calling the getCon() from run method.
    Code:
    public Connection getCon(){
        	 ctx = new javax.naming.InitialContext();
        	 ds = (javax.sql.DataSource) ctx.lookup("java:comp/env/JNDINAME"); //JNDI NAME: jdbc/Sample
        	 con = ds.getConnection();
        	 con.setAutoCommit(true);
    
            return con;
    }
    But I am getting the following error message:
    " javax.naming.Na meNotFoundExcep tion:
    Name comp/env/jdbc not found in context "java:"."

    From this point of view, my child thread is failing to open DB connection.

    Is there way to open database connection using a child thread in web container like WebSphere?
  • N002213F
    New Member
    • Sep 2007
    • 38

    #2
    try checking out this; http://java.sun.com/products/jndi/tutorial/TOC.html

    There are some examples to go with it.

    Comment

    Working...