1

Currently I am working on a section where I need to fetch records from oracle database function in spring framework. I am using package and function inside it and trying to access the same in a jdbc template

PackageName - mypakg

FunctionName - myfunc(:parm) //:parm= 3728

SQL: regn.gd.selectupdatesync= SELECT mypakg.myfunc(?) from dual // Gives correct result in SQLDeveloper via SELECT mypakg.myfunc(3728) from dual;

However in java code, when compiler reaches inside BaseService.java at dQueryForStringPS, it throws exception java.lang.NullPointerException

Logs

Exception message :null (e.getMessage())
Exception StackTrace: 
org.prj.cos.state.online.common.dao.BaseDao.getPsJdbcTemplate(BaseDao.java:589),
org.prj.cos.state.online.common.dao.BaseDao.dQueryForStringPS(BaseDao.java:171), 
org.prj.cos.state.online.common.service.BaseService.dQueryForStringPS(BaseService.java:387)

I am unable to understand the exact cause of exception and why spring is not able to call a Oracle function viz this way. Is this correct alternative way or should I need to so something else?

Code inside Implementation class- ServiceImpl.java

String strId = 
dQueryForStringPS("regn.gd.selectupdatesync", new Object[]{gdEntryFormBean.getPsCd()});

dQueryForStringPS is available inside BaseService.java

public String dQueryForStringPS(String query, Object[] paramValues) {
    return baseDao.dQueryForStringPS(query, paramValues);
}

BaseDao.java

public String dQueryForStringPS(String query, Object[] paramValues) {
     return getPsJdbcTemplate().queryForObject(SQLSelector.getQuery(query),
                                              String.class, paramValues);
}

protected JdbcTemplate getPsJdbcTemplate() {
    return TransactionLocal.getContext().getPsJdbcTemplate();
}

TransactionLocal.java

public static TransactionContext getContext() {
    return THREADLOCAL.get();
}
k10gaurav
  • 462
  • 7
  • 24
  • Are you sure that your BaseService is an instance controlled by Spring? Do you use in that class something similar to @Component? – pringi Dec 07 '16 at 13:16
  • Check `BaseDao.getPsJdbcTemplate`, there is the location of this exception. Strange thing is the empty message ... maybe one of yours ? – AxelH Dec 07 '16 at 13:18
  • Please add sample snippet for getPsJdbcTemplate() – Tom Taylor Dec 07 '16 at 14:18
  • @RajasubaSubramanian , snippet added! – k10gaurav Dec 08 '16 at 09:18
  • @AxelH , I have checked that values are being available in Object[] paramValues and question is not duplicate as value is being passed and received but causes exception during script execution. – k10gaurav Dec 08 '16 at 09:20
  • 1
    The exception is in `BaseDao.getPsJdbcTemplate` so there is no array or anything, probably `THREADLOCAL.get()` that return `null` but follow the stacktrace of the exception – AxelH Dec 08 '16 at 09:27
  • @pringi , BaseService class is the implementation class of interface IBaseService and is being controlled by Spring – k10gaurav Dec 08 '16 at 09:29
  • 1
    Please try to check with 'TransactionLocal.getContext' with 'null' before trying to use it... – Tom Taylor Dec 08 '16 at 13:33
  • That's correct! TransactionLocal.getContext() returned null. However I was trying to execute a function "SELECT mypakg.myfunc(3728) from dual" as a normal select statement but wasn't allowed using jdbcTemplate and hence wasn't successful. Also I tried using jdbcTemplate.queryForObject() that was working fine for normal select statement but failed for function call. Probably I need to check other stuff to get my function/procedure executed. – k10gaurav Dec 09 '16 at 11:51

0 Answers0