Baskar
Baskar

Reputation: 1140

Default Value for Date in SQL

If i didnt get value for created_date it throws mysql errror. How To solve this problem?

var query1 = "INSERT INTO prospect_group(
    group_name,status_id,created_date,  
    is_eligible,mom_active_fromdt,
    mom_is_savings_discussed,
    is_full_attendence,is_internal_loan) VALUES
    ('"+groupNameArray[0]+"', '"
       +groupNameArray[14]+"', '"
       +groupNameArray[1]+"', '"
       +groupNameArray[15]+"','"
       +groupNameArray[7]+"','"
       +groupNameArray[8]+"','"
       +groupNameArray[9]+"','"
       +groupNameArray[10]+"'  )";

Upvotes: 2

Views: 895

Answers (4)

faizan
faizan

Reputation: 690

You can use SYSDATE() or NOW()

Upvotes: 0

Koerr
Koerr

Reputation: 15723

Setting created_date field default value to Null

or

Use zeroDateTimeBehavior=convertToNull in the JDBC connection

example:

jdbc:mysql://192.168.6.1/test?zeroDateTimeBehavior=convertToNull

Reference: handling DATETIME values 0000-00-00 00:00:00 in JDBC

Upvotes: 1

Mohit Mehta
Mohit Mehta

Reputation: 1285

If you can add NULL set default value to NULL for created_date column and make sure that while you insert into table you'll have either date or null.

Upvotes: 0

Buddy
Buddy

Reputation: 11028

Something like this (setting the default value for the created_date field): MySQL timestamp only on create

Upvotes: 0

Related Questions