2

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]+"'  )";
xdazz
  • 158,678
  • 38
  • 247
  • 274
Baskar
  • 1,130
  • 4
  • 14
  • 25
  • @xdazz Please either revert your edit or make it better. The original one is much more readable than the current one. – Haozhun Oct 04 '12 at 06:11
  • Hi, I belive this is answered here - http://stackoverflow.com/questions/168736/how-do-you-set-a-default-value-for-a-mysql-datetime-column – Janis Lankovskis Oct 04 '12 at 06:12
  • Do you mean groupNameArray[1] is null? If so, what do you want to insert instead? – Devart Oct 04 '12 at 06:32

4 Answers4

1

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

Community
  • 1
  • 1
Koerr
  • 15,215
  • 28
  • 78
  • 108
0

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

Community
  • 1
  • 1
Buddy
  • 10,874
  • 5
  • 41
  • 58
  • Actually i am not able to give default value.I am working in application so it needs some reliable data. – Baskar Oct 04 '12 at 06:14
0

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.

Mohit Mehta
  • 1,283
  • 12
  • 21
  • I had similar problem by assigning default value to null it's solved. Try executing query >> ALTER TABLE `cp_users` CHANGE COLUMN `created_date` `created_date` DATETIME NULL DEFAULT NULL; – Mohit Mehta Oct 04 '12 at 08:06
0

You can use SYSDATE() or NOW()

faizan
  • 680
  • 1
  • 6
  • 15