JDBC Error: "Exception in thread" AWT-EventQueue-0 "java.lang.NullPointerException"

1

I am trying to create a simple Java program that can register, query and modify data from a database in MySQL. The program itself compiles me well, but when sending the Query, I miss this error: Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException

Connection Code:

import java.sql.*;

public class ConexionBD {
Connection con;

public Connection conexion(){
   try{
        Class.forName("com.mysql.jdbc.Driver");
        con = DriverManager.getConnection("jdbc:mysqldb?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC://localhost/notas","root","Marioloco456");
        System.out.println("Conexion exitosa");
   } catch (Exception e){
       System.out.println(e.getMessage());
   }return con;


}

Statement createStatement(){
    throw new UnsupportedOperationException("No soportado");
}

}

Button code:

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
   try{
        PreparedStatement pps = cn.prepareStatement("INSERT INTO periodo1(corte1,corte2,bimestral) VALUE(?,?,?,?)");
        pps.setString(1, corte1.getText());
        pps.setString(2, corte2.getText());
        pps.setString(3, bimestral.getText());
        pps.executeUpdate();
        JOptionPane.showMessageDialog(null,"Datos guardados");
   } catch (SQLException ex) {
        Logger.getLogger(PantallaPrincipal.class.getName()).log(Level.SEVERE, null, ex);
    }

}                         
    
asked by Cristian Cubillos 14.07.2018 в 23:43
source

1 answer

0

You have 4 parameters in the query " (?,?,?,?) " when you are only inserting 3 elements " corte1.corte2,bimestral "

    
answered by 14.07.2018 в 23:58