I am new to spring java. I have a controller class and repository class. what I actually want is to insert a json data into postgresql database by calling a database function(stored procedure)and return a json data as response.It shows that BAD SQL Grammar Error. Please help me to solve the issue...I am sharing my code. I am getting error in the Map<String, Object> result =insertSurveyCall.execute(params); line.
UserController.java
@RequestMapping(value="/savedbData", method = RequestMethod.POST, produces="application/json;charset=utf-8")
public String uploadFile(@RequestParam String data,HttpServletRequest request, HttpServletResponse response) throws SQLException
{
JSONObject requestJSON= new JSONObject(data);
String result="";
result=userRepository.saveDatahouse(requestJSON);
return result.toString();
}
UserRepository.java
public interface UserRepository {
String saveDatahouse( JSONObject requestJSON) throws SQLException;
}
UserRepositoryImpl.java
@Override
public String saveDatahouse(JSONObject requestJSON) throws SQLException {
JSONObject dbdata = requestJSON;
JSONObject resultJSON = new JSONObject();
Map<String, Object> params = new HashMap<String, Object>();
String reult="";
try {
PGobject pObj = new PGobject();
pObj.setType("json");
pObj.setValue(dbdata.toString());
SimpleJdbcCall insertSurveyCall = new SimpleJdbcCall(jdbcTemplate).withFunctionName("add_data_to_db");
params.put("params", pObj);
Map<String, Object> result =insertSurveyCall.execute(params);
System.out.println("result at repository::::::::::::::::::::::::");
return resultJSON.toString();
} catch (IncorrectResultSizeDataAccessException e) {
return null;
}
}