I am working on a spring batch which runs only once in a day. Please note that its not a spring boot Project rather its just Spring core along with Spring batch libraries.
I have a question, this jar will be placed in a server where IBM Websphere Was 6 server is also running. In my Jar, Would I be able to use the JNDI datasource connection available in the WAS server.
I thought even though the Jar resides on the same physical server as IBM WAS, JNDI can only be used by the apps deployed in the WAS Server . Please let me know if my understanding is wrong.
Also if you can guide me in the right direction on ways to efficently connecting to Database would be very helpful. I am just looking for reference as a starter.
ApplicationContext ctx = new ClassPathXmlApplicationContext(
"ABPBatchInfrastructure.xml",
"AgencyBillPayFileUploadApp.xml"
);
DataSource ds = (DataSource) ctx.getBean("dbDataSource");
Connection connection = ds.getConnection();
Statement st = connection.createStatement();
ResultSet rs = st.executeQuery("select name from notify.product");
XML Below
<jee:jndi-lookup id="dbDataSource"
jndi-name="jdbc/MyLocalDB"
expected-type="javax.sql.DataSource" />
Stack Trace below
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dbDataSource': Invocation of init method failed; nested exception is javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1420)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)