I have a problem to get connection to my database via java and jboss esb 4.2. I have build a .war package and deployed it on the jboss server. But i am gettin error while trying to connect to the database.
Java Method
Connection conn = null;
PreparedStatement stmt = null;
ResultSet rs = null;
try {
Context initContext = new InitialContext();
Context envContext = (Context) initContext.lookup("java:/comp/env");
DataSource ds = (DataSource) envContext.lookup("jdbc/VINService");
String sql = "SELECT ...";
conn = ds.getConnection();
stmt = conn.prepareStatement(sql);
...
jboss-web.xml
<resource-ref>
<res-ref-name>jdbc/VINService</res-ref-name>
<jndi-name>java:jdbc/VINService</jndi-name>
<res-type>javax.sql.DataSource</res-type>
</resource-ref>
web.xml
<resource-ref>
<description>VINService</description>
<res-ref-name>jdbc/VINService</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
VIN_Service-ds.xml
<?xml version="1.0" encoding="UTF-8"?>
<datasources>
<local-tx-datasource>
<jndi-name>jdbc/VINService</jndi-name>
<connection-url>jdbc:mysql://url/db?autoReconnect=true</connection-url>
<driver-class>com.mysql.jdbc.Driver</driver-class>
<user-name>name</user-name>
<password>password</password>
<min-pool-size>5</min-pool-size>
<max-pool-size>20</max-pool-size>
<idle-timeout-minutes>0</idle-timeout-minutes>
<exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name>
<check-valid-connection-sql>SELECT 1 FROM vehiclecache limit 1</check-valid-connection-sql>
</local-tx-datasource>
</datasources>
What am i doing wrong? I am getting Nullpointer Error at
conn = ds.getConnection()
so it isn't finding the datasource. Can anybody help me?