Error inserting column without default value

-2

good I have two tables a user and another type of user which are related I would like to save the data in java mysql netbeans that when entering the data in user they load me in type of user to give the level or privilege in the system I did an essay because of versad I am new to this and this is part of the university project, I made a sentence but it gave me the following, this is the sentence:

try {
    PreparedStatement ap=con.prepareStatement("INSERT INTO tipo_usuario(regente,almacenista,auxiliar) VALUES(?,?,?)");
    ap.setInt(1, cbtipo_usuario.getSelectedIndex());
    ap.setInt(2, cbtipo_usuario.getSelectedIndex());
    ap.setInt(3, cbtipo_usuario.getSelectedIndex());
    ap.executeUpdate();

    PreparedStatement pps = con.prepareStatement("INSERT INTO usuario (usuario,contraseña,nombre,apellido,nacio,cedula,telefono,sexo,direccion,tipo_usuario) VALUES(?,?,?,?,?,?,?,?,?,?)");

    pps.setString(1, txtusu.getText());
    pps.setString(2, contra.getText().toString());
    pps.setString(3, txtnombre.getText());
    pps.setString(4, txtapellido.getText());
    pps.setString(5, cbnacion.getSelectedItem().toString());
    pps.setString(6, txtcedul.getText());
    pps.setString(7, cbsexo.getSelectedItem().toString());
    pps.setString(8, cbope.getSelectedItem().toString() + "" + txttelf.getText());
    pps.setString(9, txtdireccion.getText());
    pps.setInt(10, cbtipo_usuario.getSelectedIndex());

    pps.executeUpdate();
    JOptionPane.showMessageDialog(null, "DATOS REGISTRADOS");

but running gives me the following error: Error here: java.sql.SQLException: The field 'user_type_type_user_type' does not have a default value

How can I fix it or do it thanks to the person who can help me a thousand thanks in advance

    
asked by Carlos Ariza 16.12.2017 в 04:02
source

1 answer

0

The fields in your database are poorly defined. As you have defined at this time, you have to pass the value to the field, which you are not doing.

I suppose you wanted your usertype to be an autonumerico, therefore you had to set the field with the flag AUTO_INCREMENT, so that it only took a value.

Your create should have been something like this:

CREATE TABLE tipo_usuario(
     idtipo_usuario INT NOT NULL AUTO_INCREMENT,
     ....
);

If not, you should give it a value when doing the insert, but I do not know if that's what you wanted.

    
answered by 16.12.2017 в 04:18