Results 1 to 7 of 7

Thread: getSimpleJdbcTemplate().query() problem

  1. #1
    Join Date
    Dec 2012
    Posts
    4

    Default getSimpleJdbcTemplate().query() problem

    Hello,

    When I execute the following code, on Oracle:

    Code:
    public static String QUERY_DATOS_LINEA="SELECT LIN_ID,LIN_IDF FROM CVI_LINEAS@SAE_DB";
    
    List<DatosLinea> lista = getSimpleJdbcTemplate().query(QUERY_DATOS_LINEA, new ParameterizedRowMapper<DatosLinea>(){
    			public DatosLinea mapRow(ResultSet rs, int rowNum) throws SQLException {
    				DatosLinea lin = new DatosLinea();
    				lin.setId(rs.getInt("LIN_ID"));
    				lin.setIdf(rs.getString("LIN_IDF"));
    				return lin;
    			}
    I get the following error:

    Exception in thread "main" org.springframework.jdbc.BadSqlGrammarException: StatementCallback; bad SQL grammar [SELECT LIN_ID,LIN_IDF FROM CVI_LINEAS@SAE_DB]; nested exception is java.sql.SQLSyntaxErrorException: ORA-02041: client database did not begin a transaction
    ORA-02063: preceding line from SAE_DB


    When I execute the query directly on TOAD, it runs ok, but with the getSimpleJdbcTemplate().query method, it doesn't work.

    I know the problem is in the '@SAE_DB' part, maybe it's not compatible with this method, but that's the only way I know to access the database, since it is in another server and I can't access directly from the dblink I was given. If I don't use it, it tells me that the table CVI_LINEAS does not exist.

    Anyone can help? If you need more info, just ask.

    PS: sorry for the lack of details, but I'm not used to work with Oracle

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,624

    Default

    Judging from the stacktrace you are running without transactions and apparently this feature needs transactions. So configure transactions (even if they are readonly).
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Dec 2012
    Posts
    4

    Default

    I'm not the DB Admin. Is there any way to configure it directly in my code?

  4. #4
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,624

    Default

    It has nothing to do with your db it has all to do with the absence of proper tx configuration in your application. I suggest a read of the spring reference guide.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  5. #5
    Join Date
    Dec 2012
    Posts
    4

    Default

    In my applicationContext.xml file I have the following configuration:

    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSou rceTransactionManager">
    <property name="dataSource" ref="dataSource"/>
    </bean>

    I'm using the oracle.jdbc.driver.OracleDriver driver contained in the ojdbc6-11.2.0.3.jar

    Shouldn't the transactions be managed automatically?

    I'm I seeing it wrong?

  6. #6
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,624

    Default

    Again read the reference guide... Only a transaction manager isn't enough. You only configured the how (transactionmanager) not the WHEN (transaction attributes/configuration).
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  7. #7
    Join Date
    Dec 2012
    Posts
    4

    Default

    Can you please point me to any transaction management/configuration example? I've been reading the reference guide since this morning and still I can't figure it out.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •