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>