0

I'm facing an issue when using NamedParameterJdbcTemplate in my Spring apps to query data from Oracle db.

from insomnia/postman i send parameter with body "IDBILL":"9999" and i received the data billing, but when i tried negative scenario ( Oracle service stoped ) , the apps still return data

i've tried another id billing 8888 and return exception because oracle db stoped as i expected, but after that i've tried to previous id billing 9999 and it return the data

why it return the data even though the database services stoped ? need some advice to solving this problem...thank u ...

here is my function to run the sql :

public JsonObject runServicesNPJT(String psQUERY,ConcurrentHashMap<String, String> chmParam )  
{
    JsonObject oReturn = new JsonObject();
    String json ="";
    namedParameterJT = new NamedParameterJdbcTemplate(ds);
    
    try {
        //SqlParameterSource paramSQL = new MapSqlParameterSource().addValue("tahun", "2021");
        SqlParameterSource paramSQL = new MapSqlParameterSource();
        MapSqlParameterSource msps  = new MapSqlParameterSource();
        for (Entry<String, String> entry : chmParam.entrySet()) {
            msps.addValue(entry.getKey(), entry.getValue());        
        }
        
        paramSQL = new MapSqlParameterSource().addValues(chmParam);
        Map<String, Object>  rs = namedParameterJT.queryForMap(psQUERY, paramSQL);
        json = gson.toJson(rs);
        
    } catch (Exception e) {
        // TODO: handle exception
        if(e.toString().contains("IO"))
        {
            return response.sendResponse(ResponseCode.TIMEOUT, ResponseCode.TIMEOUT.description);
        }else {
            
        }
    }
    JsonElement jeReturn = JsonParser.parseString(json);
    return jeReturn.getAsJsonObject();
    
}

this application.properties

spring.application.name=API-MultiBiller Service Engine
spring.application.version=1.0.0-1



#--YA-- db 
spring.datasource.url=jdbc:oracle:thin:@localhost:9981:xe
spring.datasource.username=MSDATA
spring.datasource.password=MSDATA
spring.datasource.driver-class-oracle.jdbc.driver.OracleDriver
spring.cache.type=none

#spring.datasource.tomcat.validation-query=SELECT 1
#spring.datasource.tomcat.validation-query-timeout=5000
#spring.datasource.tomcat.test-on-borrow=true
#spring.datasource.tomcat.test-on-connect=true

# HikariCP settings
# spring.datasource.hikari.*
spring.datasource.hikari.connection-timeout=5000
#spring.datasource.hikari.maximum-pool-size=5

this my pom.xml

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-hateoas</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    
    <!-- YA untuk Oracle JDBC driver support oraclexe 11g-->
    <!-- https://mvnrepository.com/artifact/com.oracle.database.jdbc/ojdbc10 -->
    <dependency>
        <groupId>com.oracle.database.jdbc</groupId>
        <artifactId>ojdbc8</artifactId>
        <version>12.2.0.1</version>
    </dependency>
    
    <!-- https://mvnrepository.com/artifact/org.json/json -->
    <dependency>
        <groupId>org.json</groupId>
        <artifactId>json</artifactId>
        <version>20211205</version>
    </dependency>
            

    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jdbc</artifactId>
    </dependency>
    <!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        </dependency>
    
    <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
    </dependency>
</dependencies>
kumin
  • 21
  • 5
  • Does it only return values while the db is stopped that you once requested when the database was running? If so, then it must be some sort of caching going on. If you can get a value back that you've never asked for before, then something super crazy is going on since there's no reason for that value to have ever been pulled from the db while it was running. – CryptoFool Feb 11 '22 at 04:20
  • yes i was thought about that caching....and i've tried with add `spring.cache.type=none` in application.properties and tested send request with **"IDBILL":"6666"** after i get a data , i stoped the database service, and send second request again with same **IDBILL** it still return , and send third request still the same, and finally the fourth request it stop and response time out....any clue where i can check ? – kumin Feb 11 '22 at 05:23

0 Answers0