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

前端 未结 10 1690
一向
一向 2020-11-27 11:01

I get an exception (see below) if I try to do

resultset.getString(\"add_date\");

for a JDBC connection to a MySQL database containing a DA

10条回答
  •  情歌与酒
    2020-11-27 11:24

    I stumbled across this attempting to solve the same issue. The installation I am working with uses JBOSS and Hibernate, so I had to do this a different way. For the basic case, you should be able to add zeroDateTimeBehavior=convertToNull to your connection URI as per this configuration properties page.

    I found other suggestions across the land referring to putting that parameter in your hibernate config:

    In hibernate.cfg.xml:

    convertToNull
    

    In hibernate.properties:

    hibernate.connection.zeroDateTimeBehavior=convertToNull
    

    But I had to put it in my mysql-ds.xml file for JBOSS as:

    convertToNull
    

    Hope this helps someone. :)

提交回复
热议问题