Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JDBC Template exception table or view does not exist but it actually exists

I'm trying to get some data from Oracle DB using Spring JDBCTemplate:

String query = "SELECT * FROM snow.ar_incident WHERE ROWNUM < 10";

    Map<String, List<Attachment>> map = jdbcTemplate.query(query, new ResultSetExtractor<Map<String, List<Attachment>>>() {

        @Override
        public Map<String, List<Attachment>> extractData(ResultSet rs) throws SQLException, DataAccessException {
            Map<String, List<Attachment>> map = new HashMap<>();
            //Mapping results to map
            return map;
        }
    });

But I'm always getting an exception only for ar_incidient table:

Caused by: org.springframework.jdbc.BadSqlGrammarException: StatementCallback; bad SQL grammar [SELECT * from snow.ar_incident WHERE ROWNUM < 10]; nested exception is java.sql.SQLSyntaxErrorException: ORA-00942: table or view does not exist

This code works perfectly fine for other tables but not for this one. I also tried to get data from this table using core Java sql connection:

Class.forName("oracle.jdbc.driver.OracleDriver");  
Connection con = DriverManager.getConnection(connString, user, pass);    
Statement stmt=con.createStatement();   
ResultSet rs = stmt.executeQuery("SELECT * from snow.ar_incident WHERE ROWNUM < 10");  

And it worked without a problem, same when I run the query in SQL Developer. I have checked many times connection details for the both solutions and they are identical. Why can't I access ar_incident table using JDBCTemplate?

like image 795
Michael Dz Avatar asked Nov 08 '22 02:11

Michael Dz


1 Answers

Please check if grants are there and if you need to prefix table name with schema.table_name.

like image 168
Rishikesh Fanse Avatar answered Nov 14 '22 22:11

Rishikesh Fanse