1

I'm having a problem.

I have a table called issuebook in my MYsql database where there are 5 columns.

The columns are: memberid, membername, bookname, issuedate, returndate.

So I only want to insert data in 3 columns in memberid, membername, bookname and leave the other 2 columns blank for now (because in those columns when admin gives date then data will be inserted in those columns).

But whenever I try to insert it, it shows me an error like this:

java.sql.SQLException: Field 'issuedate' doesn't have a default value

My code is given below:

String bname,name,id;
id = Start.ID1;
name = Start.NAME1;
bname = bookBox.getSelectedItem().toString();
try {
    pst = con.prepareStatement("insert into issuebook(memberid,membername,bookname)values(?,?,?)");
    pst.setInt(1, Integer.parseInt(id));
    pst.setString(2, name);
    pst.setString(3, bname);
    pst.executeUpdate();

    JOptionPane.showMessageDialog(null, "Your Request is sent.");
    
}
catch (SQLException e1) {
    e1.printStackTrace();
}

My database table :

MK.Whridoy
  • 68
  • 1
  • 8

1 Answers1

1

The problem is with issuedate column definition. As you have mentioned in comment - it is defined as not null.

Your SQL ommit issuedate column in into clause which means that query will try to insert null value into it. You have to provide date in your SQL or redefine issuedate column to allow null values.

Check out this SO thread Field doesn't have a default values.

Lukasz Blasiak
  • 642
  • 2
  • 10
  • 16