In this proyect that I’m actually worked out, Im still try to find out the error of the conection of the database in a Java Bean, however I cannot find where is it exactily.
This the code that conects into the database using the java beans in a java web application, and I received as a result error 500 in the output.
@ManagedBean public class TestJSON { private static URL url; private static String sitio = "http://localhost:8088/"; public static int postJSON(Empresarios empresarios) throws IOException{ url = new URL(sitio+"Empresarios/guardar"); HttpURLConnection http; http = (HttpURLConnection)url.openConnection(); try { http.setRequestMethod("POST"); }catch(ProtocolException e) { e.printStackTrace(); } http.setDoOutput(true); http.setRequestProperty("Accept","application/json"); http.setRequestProperty("Content-Type", "application/json"); String data = "{" + ""codigo":""+empresarios.getCodigo() + "","arl":""+empresarios.getArl() + "","cargo":""+empresarios.getCargo() + "","dependencia":""+empresarios.getDependencia() + "","eps":""+empresarios.getEps() + "","fecha":""+empresarios.getFecha() + "","nombre":""+empresarios.getNombre() + "","pensiones":""+empresarios.getPensiones() + "","sueldo":""+empresarios.getSueldo() + ""}"; byte[] out = data.getBytes(StandardCharsets.UTF_8); OutputStream stream = http.getOutputStream(); stream.write(out); int respuesta = http.getResponseCode(); System.out.println(respuesta); http.disconnect(); return respuesta; } }
WWN27 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.