PostgresDB JNDI problems
gneeri Jul 9, 2002 8:38 PMHi-
I vacillated between putting this here or in the newbie section, but this seemed more appropriate. I hope this is the right place.
Anyway, after following the information in several forum postings (particularly http://www.jboss.org/modules/bb/index.html?module=bb&op=viewtopic&t=forums/ I went ahead and set up PostgresDS for my Jboss 3.0.0 implementation. During the startup process, I get no errors and in fact get a success message for initialization of the postgres-service.xml. I also get the following message:
[PostgresDS] Bound connection factory for resource adapter 'JBoss LocalTransaction JDBC Wrapper' to JNDI name 'java:/PostgresDS'
By way of testing the Postgres datasource, I wrote the following little program to test the connection.
import java.sql.*;
import javax.sql.*;
import javax.naming.*;
import java.util.*;
public class testConn {
 public static void main(String[] args){
 Context ctx = null;
 Properties h = new Properties();
 h.put(Context.INITIAL_CONTEXT_FACTORY,
 "org.jnp.interfaces.NamingContextFactory");
 h.put(Context.PROVIDER_URL,
 "jnp://localhost:1099");
 testConn tc=new testConn();
 try {
 ctx = new InitialContext(h);
 javax.sql.DataSource ds
 = (javax.sql.DataSource) ctx.lookup ("PostgresDS");
 java.sql.Connection conn = ds.getConnection();
 Statement stmt = conn.createStatement();
 stmt.execute("select * from test");
 ResultSet rs = stmt.getResultSet();
 tc.getTest(rs);
 stmt.close();
 conn.close();
 } catch (NamingException e) {
 System.out.println("Could not get JNDI datasource.");
 System.out.println("ERROR: " + e.toString());
 }catch (SQLException se){}
 try {ctx.close();}
 catch (Exception e) {}
 }
 public void getTest(ResultSet rs)throws SQLException{
 while (rs.next()) {
 String test = rs.getString("NAME");
 System.out.println("TEST: "+ test);
 }
 }
}
The result is "NameNotFoundException: PostgresDS not bound". I've used similar (context) syntax to test JNDI for a session bean that I wrote and that works fine.
Any thoughts? I'm a bit perplexed.
Thanks,
jonathan
 
    