MySQL datasource error
jaleyba Apr 6, 2006 6:52 AMHi
I've a simple web application in JBoss AS that will need to connect to a MySQL DB then I did in WEB-INF of deployed:
jboss-web.xml
<?xml version="1.0" encoding="UTF-8"?> <jboss-web> <resource-ref> <res-ref-name>jdbc/MySQLDB</res-ref-name> <res-type>javax.sql.DataSource</res-type> <jndi-name>java:MySQLDB</jndi-name> </resource-ref> </jboss-web>
web.xml
<resource-ref> <description>The default MySQL DS</description> <res-ref-name>jdbc/MySQLDB</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref>
Adn in my code I did:
public static Connection getConnection() throws Exception { Connection conn = null; Context envContext = null; logger.info( "NOTIFICATIONS: Trying to access to Connection"); try { Context initContext = new InitialContext(); envContext = (Context) initContext.lookup(DBConnection.LOOKUP_LABEL); } catch (NamingException ne) { logger.error( "NOTIFICATIONS: Error ne en LOOKUP al intentar conseguir conectar al DB pool: " + ne.getMessage()); } catch (Exception e) { logger.error( "NOTIFICATIONS: Error e en LOOKUP al intentar conseguir conectar al DB pool: " + e.getMessage()); } try { DataSource ds = (DataSource) envContext.lookup(DBConnection.DATASOURCE_LABEL); conn = ds.getConnection(); } catch (NamingException ne) { logger.error( "NOTIFICATIONS: Error ne en DATASOURCE al intentar conseguir conectar al DB pool: " + ne.getMessage()); } catch (NullPointerException npe) { logger.error( "NOTIFICATIONS: Error npe en DATASOURCE al intentar conseguir conectar al DB pool: " + npe.getMessage()); } catch (SQLException sqle) { logger.error( "NOTIFICATIONS: Error sqle en DATASOURCE al intentar conseguir conectar al DB pool: " + sqle.getMessage()); } catch (Exception e) { logger.error( "NOTIFICATIONS: Error en DATASOURCE al intentar conseguir conectar al DB pool: " + e.getMessage()); }
But when my app try to connect I got the message:
12:35:06,950 INFO [DBConnection] NOTIFICATIONS: Trying to access to Connection 12:35:06,955 ERROR [DBConnection] NOTIFICATIONS: Error ne en DATASOURCE al intentar conseguir conectar al DB pool: Could not dereference object
Could somebody tell me what am I doing wrong ?
Thanks in advance
J