Hello
I JBoss/mySQL database. I also put mysql-connection into \jboss\server\default\lib.
I have a bean that have a function getConnection as:
private Connection getConnection() throws SQLException {
try {
Context jndiCntx = new InitialContext();
DataSource ds = (DataSource) jndiCntx.lookup("java:TestDatabase");
return ds.getConnection();
}
catch (NamingException ne) {
throw new EJBException(ne);
}
}
However, this function always give a null value (I test by using another function inside this bean). I also try one more way:
------------------------------------------------
private Connection getConnection() throws SQLException {
try {
Properties pro = new Properties();
pro.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
pro.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
pro.put("java.naming.provider.url","localhost:1099");
Context jndiCntx = new InitialContext(pro)
DataSource ds = (DataSource) jndiCntx.lookup("java:TestDatabase");
return ds.getConnection();
}
catch (NamingException ne) {
throw new EJBException(ne);
}
}
However both of them do not work
Could you please help. What i am wrong here
-------------------------
I have a test-ds.xml in boss\server\default\deploy folder as:
<local-tx-datasource>
<jndi-name>TestDatabase</jndi-name>
<connection-url>jdbc:mysql://localhost:1099/database</connection-url>
<driver-class>com.mysql.jdbc.Driver</driver-class>
<user-name>jboss</user-name>
pass
</local-tx-datasource>
bosscmp-jdbc.xml file
<jbosscmp-jdbc>
java:/TestDatabase
<datasource-mapping>mySQL</datasource-mapping>
<preferred-relation-mapping>relation-table</preferred-relation-mapping>
</jbosscmp-jdbc>