[jboss-user] [JNDI/Naming/Network] - lookup database source weird problem
joshuayeo
do-not-reply at jboss.com
Thu May 3 23:31:50 EDT 2007
Hi all ,
I am using jdk 1.6.0_01 and jboss 4.0.5.GA.
I have setup jndi lookup in my startup servlet init() method , however it did not lookup the jndi database name at all.
It always give me error message cannot lookup the jndi name.
Anyone have any ideas what is happening here ? Thanks
Below is the startup servlet for my webapps:
public class AdminStartupServlet extends HttpServlet {
protected Logger logger = LoggerManager.getLogger();
public void init(ServletConfig config) throws ServletException {
super.init(config);
DatabaseAction databaseAction = ActionManager.getDatabaseAction();
try{
databaseAction.process();
} catch(NamingException ne){
ne.printStackTrace();
} catch(Exception ex){
ex.printStackTrace();
}
}
}
This is DatabaseAction :
public class DatabaseAction {
protected DatabaseAction() {
}
public void process() throws Exception
{
try {
OracleDatabaseManager.config();
} catch(Exception ex) {
throw new Exception("Fail to config ORACLE database connection.", ex);
}
}
}
This is the Database Manager to lookup database jndi name
public class OracleDatabaseManager {
protected static DataSource oracleDS;
public static synchronized void config() throws Exception {
try{
InitialContext initialContext = new InitialContext();
oracleDS = (javax.sql.DataSource) initialContext.lookup("jdbc/OracleDS");
}catch(Exception ex){
ex.printStackTrace();
}
}
public static Connection getOracleConnection() throws Exception {
try {
//InitialContext initialContext = new InitialContext();
//oracleDS = (javax.sql.DataSource) //initialContext.lookup("jdbc/OracleDS");
return oracleDS.getConnection();
} catch (Exception ex) {
throw new Exception(ex);
}
}
}
web.xml resource-ref tag
<resource-ref>
Oracle DB Connection
<res-ref-name>jdbc/OracleDS</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
jboss-web.xml tag
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
jboss.jca:service=LocalTxCM,name=jdbc/OracleDS
<context-root>/</context->
<resource-ref>
<res-ref-name>jdbc/OracleDS</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<jndi-name>jdbc/OracleDS</jndi-name>
</resource-ref>
</jboss-web>
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4043062#4043062
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4043062
More information about the jboss-user
mailing list