java - Spring Transactional not using same JDBC connection -


can please tell me why sql exception "invalid object #emp_temp" if running both queries under same transaction?

@transactional public map<string, eventtype> findeventsbydaterange(final date starttimestamp, final date endtimestamp) throws exception {     log.debug("fetching events data");     string event_query = "select id, name, status, joindate #emp_temp employee joindate >= ? , joindate < ?";      this.jt.execute(event_query, new preparedstatementcallback<boolean>() {         @override         public boolean doinpreparedstatement(preparedstatement preparedstatement) throws sqlexception, dataaccessexception {             preparedstatement.settimestamp(1, new java.sql.timestamp(starttimestamp.gettime()));             preparedstatement.settimestamp(2, new java.sql.timestamp(endtimestamp.gettime()));             return preparedstatement.execute();         }     });     //this.jt.execute(event_query);      return this.jt.query("select * #emp_temp "             , dataextractor.eventdataextractor); } 

however if change code below doesn't complaint. problem in approach cannot pass parameters first query:

@transactional public map<string, eventtype> findeventsbydaterange(final date starttimestamp, final date endtimestamp) throws exception {     log.debug("fetching events data");     string event_query = "select id, name, status, joindate #emp_temp employee joindate >= '2015-07-13 00:00:00.000' , joindate < '2015-07-14 00:00:00.000'";      /*this.jt.execute(event_query, new preparedstatementcallback<boolean>() {         @override         public boolean doinpreparedstatement(preparedstatement preparedstatement) throws sqlexception, dataaccessexception {             preparedstatement.settimestamp(1, new java.sql.timestamp(starttimestamp.gettime()));             preparedstatement.settimestamp(2, new java.sql.timestamp(endtimestamp.gettime()));             return preparedstatement.execute();         }     });*/     this.jt.execute(event_query);      return this.jt.query("select * #emp_temp "             , dataextractor.eventdataextractor); } 

finally found out root cause of problem not spring sql server.

in sql server 2005, sql server 2000, , sql server 7.0, prepared statements cannot used create temporary objects , cannot reference system stored procedures create temporary objects, such temporary tables. these procedures must executed directly.

since trying create temp table jdbctemplate method execute(string sql, preparedstatementcallback action) uses prepared statement therefore not working.

instead of when created temp table using execute(string sql) working.


Comments

Popular posts from this blog

php - Zend Framework / Skeleton-Application / Composer install issue -

c# - Better 64-bit byte array hash -

python - PyCharm Type error Message -