I am trying to introduce a JSON String into H2 Data Base. It is a Spring based API-REST.
Here is the Java code used to call the embedded DataBase:
URL url = new URL("http://127.0.0.1:8080/messages/");
System.out.println("URL: " + url.toString());
HttpURLConnection conexion = (HttpURLConnection) url.openConnection();
conexion.setDoOutput(true);
conexion.setDoInput(true);
conexion.setRequestMethod("POST");
conexion.setRequestProperty("Accept", "application/json");
conexion.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
OutputStreamWriter wr = new OutputStreamWriter(conexion.getOutputStream(), "UTF-8");
String mensaje = message.convertToJson();
System.out.println("Mensaje: " + mensaje);
wr.write(mensaje);
wr.flush();
wr.close();
For some reason wr.write(mensaje)
does not do what it is suppose to do. The execution does not return any error nor exception, everything seems to work fine.
Note that the Json showed in the DataBase content image was inserted using Postman. But after running the application and the API-Rest the other Json string was not included.
Thank you, Héctor