0
votes

I get this error when I try reading from an oracle database:

java.sql.SQLSyntaxErrorException: ORA-00942: table or view does not exist

However, I've tested the query with same credentials on a client and it works. What could be wrong.

Find below my connection setup:

@Bean(name="eJDBCDatasource")
@ConfigurationProperties(prefix = "spring.datasourceexample")
public DataSource eJDBCDatasource(){
    return DataSourceBuilder.create().build();
}

@Bean(name="exampleNmpJDBCTemplate")
public NamedParameterJdbcTemplate exampleNmpJDBCTemplate(@Qualifier("eJDBCDatasource") DataSource eJDBCDatasource){
    return new NamedParameterJdbcTemplate(eJDBCDatasource);
}

and my configuration:

spring.datasourceexample.url=jdbc:oracle:thin:@//X.X.X.X:1521/EXDB
spring.datasourceexample.username=read
spring.datasourceexample.password=readp
spring.datasourceexample.driverClassName=oracle.jdbc.driver.OracleDriver
spring.datasourceexample.max-active=50
spring.datasourceexample.initial-size=20
spring.datasourceexample.max-idle=5
spring.datasourceexample.min-idle=1
spring.datasourceexample.test-while-idle=true
spring.datasourceexample.testOnBorrow=false
spring.datasourceexample.validationQuery=SELECT 1
spring.datasourceexample.time-between-eviction-runs-millis=5000 
spring.datasourceexample.min-evictable-idle-time-millis=60000
spring.datasourceexample.unreturnedConnectionTimeout=30000
spring.datasourceexample.debugUnreturnedConnectionStackTraces=true
spring.datasourceexample.maxIdleTimeExcessConnections=300

and the query:

@Autowired
NamedParameterJdbcTemplate exampleNmpJDBCTemplate;

public Boolean isExample(String Id) {

    SqlParameterSource param = new MapSqlParameterSource()
            .addValue("id", Id);
    List result = (List) exampleNmpJDBCTemplate.queryForList(this.examplesearchQuery, param);
    return !result.isEmpty();
}
1
Oracle does not lie. If you login with the same username with sqlplus, what happens?OldProgrammer
It works. I've solved this issue. Thanks 👍🏽Winnie

1 Answers

0
votes

Solved the issue I had other datasource connections in the app. Hence I needed to add the @Qualifier annotation.

@Autowired
@Qualifier("exampleNmpJDBCTemplate")
NamedParameterJdbcTemplate exampleNmpJDBCTemplate;