Posts

Showing posts with the label jdbc

how to Fix JAVA error NullPointerException(with jdbc)

Image
Clash Royale CLAN TAG #URR8PPP how to Fix JAVA error NullPointerException(with jdbc) I do not speak English well An error occurred while doing JDBC. I knew during coding that ' executequery ' should only be done by ' select ' in the database, and ' insert ' should be ' executeupdate '. However, when I did executeupdate, I had a problem with the variable and changed it to " int " Then an error occurred. How can it be carried out as I intended? I'll show you the code. import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; public class EdgeCloud { static ArrayList<String> deleteDB = new ArrayList<>(); static ArrayList<String> DBCarIP = new ArrayList<>(); static ArrayList<String> Contain...

Passing an ArrayList of Java Objects While Calling a Stored Procedure Using Spring JDBC

Image
Clash Royale CLAN TAG #URR8PPP Passing an ArrayList of Java Objects While Calling a Stored Procedure Using Spring JDBC What is the Right approach for passing an arraylist of java objects to a stored procedure. Internally the Stored procedure expects a collection of a particular data type . Currently i am trying the following but it is not working example : //Setting the JdbcCall Object SimpleJdbcCall jdbcCall = new SimpleJdbcCall(jdbcTemplate) .withProcedureName("name") .withCatalogName("catalog") .withoutProcedureColumnMetaDataAccess() .declareParameters(new SqlParameter( "input_parameter1", Types.ARRAY, "SAMPLELIST"), new SqlOutParameter("P_ERROR_MESSAGE" , Types.VARCHAR)); //Creating the list of objects to be sent to proc List<SampleObject> list = new ArrayList<>...

Storing a Date value with JDBC and Postgres

Image
Clash Royale CLAN TAG #URR8PPP Storing a Date value with JDBC and Postgres I have made a formulary with NetBeans using java. In that formulary I have a field JDateChooser. The problem is when I try to insert that value in Postgres database: public void insertarDatos(Usuario u){ try { String sql = "INSERT INTO usuario( dni, nombre, apellidos, correo, " + "telefono, usuario, clave, fecha, foto)n" + "VALUES (?, ?, ?, ?, ?, ?, ?, '"+u.getFecha()+"', ?);"; PreparedStatement ps=con.con.prepareStatement(sql); ps.setString(1, u.getDni()); ps.setString(2, u.getNombre()); ps.setString(3, u.getApellidos()); ps.setString(4, u.getCorreo()); ps.setString(5, u.getTelefono()); ps.setString(6, u.getUsuario()); ps.setString(7, u.getClave()); ps.setBinaryStream(8, u.getFis(), u.getLongitudBytes()); boolean ejecucion=con.ejecutarSQL(ps)...