[jboss-user] [JNDI/Naming/Network] - Re: Need to configure JNDI

new_to_jboss_4 do-not-reply at jboss.com
Wed Nov 28 17:26:55 EST 2007


here's what i have a sample application to test the jboss jndi..

import java.sql.Connection; 
import java.sql.PreparedStatement; 
import java.sql.ResultSet; 
import java.sql.SQLException; 
import javax.naming.InitialContext;
import javax.naming.Context;
import java.util.Hashtable;
import javax.sql.DataSource;

class test {    

 public static void main(String[] args) throws SQLException {        
 Connection con = null;        
 PreparedStatement stmt = null;        
 String query = "SELECT sysdate FROM DUAL";                
 try {            
 //con = Database.connectWeblogic();            
 con = connectJboss();            
 stmt = con.prepareStatement(query);            
 stmt.execute();            
 ResultSet rs = stmt.getResultSet();            
 while(rs.next()){                
 System.out.println(rs.getString(1));            
 }        
 }catch(SQLException e){            
 e.printStackTrace();
 //System.err.println(e.getMessage());            
 throw new SQLException("Fault: Couldn't Fetch Fields");        
 }finally {
 //Database.disconnect(con);
 }            
 } 
 
 public static Connection connectJboss() throws SQLException {
 Context ctx = null;        
 //Hashtable<String, String> ht = new Hashtable<String, String>();        
 Hashtable ht = new Hashtable();        
 ht.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"); 
 ht.put(Context.PROVIDER_URL, "fb-linux1.corp.adobe.com:8080"); 
 Connection con = null;                
 try {            
 ctx = new InitialContext(ht);
  DataSource ds = (DataSource) ctx.lookup("WTSN");            
  con = ds.getConnection();        
  } catch (Exception e) {            
  e.printStackTrace();
 // System.out.println (e.getMessage());            
  throw new SQLException("Database connection failed");        
  }                        
  return con;
}
}



i get this error...

java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory not found in [file:/usr/share/java/libgcj-3.4.3.jar, file:./, core:/]
   at java.net.URLClassLoader.findClass(java.lang.String) (/usr/lib/libgcj.so.5.0.0)
   at gnu.gcj.runtime.VMClassLoader.findClass(java.lang.String) (/usr/lib/libgcj.so.5.0.0)
   at java.lang.ClassLoader.loadClass(java.lang.String, boolean) (/usr/lib/libgcj.so.5.0.0)
   at _Jv_FindClass(_Jv_Utf8Const, java.lang.ClassLoader) (/usr/lib/libgcj.so.5.0.0)
   at java.lang.Class.forName(java.lang.String, boolean, java.lang.ClassLoader) (/usr/lib/libgcj.so.5.0.0)
   at javax.naming.spi.NamingManager.getInitialContext(java.util.Hashtable) (/usr/lib/libgcj.so.5.0.0)
   at javax.naming.InitialContext.getDefaultInitCtx() (/usr/lib/libgcj.so.5.0.0)
   at javax.naming.InitialContext.getURLOrDefaultInitCtx(java.lang.String) (/usr/lib/libgcj.so.5.0.0)
   at javax.naming.InitialContext.lookup(java.lang.String) (/usr/lib/libgcj.so.5.0.0)
   at test.connectJboss() (Unknown Source)
   at test.main(java.lang.String[]) (Unknown Source)
java.sql.SQLException: Database connection failed
   at test.connectJboss() (Unknown Source)
   at test.main(java.lang.String[]) (Unknown Source)
Exception in thread "main" java.sql.SQLException: Fault: Couldn't Fetch Fields
   at test.main(java.lang.String[]) (Unknown Source)

-----------------

Pls advice how to rectify this!!!

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4108704#4108704

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4108704



More information about the jboss-user mailing list