0

I have a database table whose structure is as follows:

enter image description here

To retrieve the data i have used query Select * from mytable

In java I am using resultset rs

My code is

if(rs.next())
{
    str[0] = rs.getString("id").trim();
    str[1] = rs.getString("userid").trim();
    str[2] = rs.getString("keyword").trim();
    str[3] = rs.getString("field").trim();
    str[4] = rs.getString("type").trim();
    str[5] = rs.getString("assignee").trim();
    str[6] = rs.getString("category").trim();
    str[7] = rs.getString("subcategory").trim();
    str[8] = rs.getString("publicationDateFrom").trim();
    str[9] = rs.getString("publicationDateTo").trim();
    str[10] = rs.getString("date").trim();
    str[11] = rs.getString("time").trim();
    str[12] = rs.getString("assigneeNames").trim();
    str[13] = rs.getString("categoryNames").trim();
    str[14] = rs.getString("subcategoryNames").trim();              
}

The problem is i am always getting exception of

Value '0000-00-00' can not be represented as java.sql.Date[Ljava.lang.StackTraceElement;@42c7d3

Please point me in right direction.

Voonic
  • 4,667
  • 3
  • 27
  • 58

3 Answers3

3

you need add zeroDateTimeBehavior=convertToNull to your mysql connection URI. Check here for more details

Abimaran Kugathasan
  • 31,165
  • 11
  • 75
  • 105
0

Firstly do one thing .. change column to nullable and use following code feching the date from resultset

str[10] = rs.getTimestamp("date").toString();
Yograj Sudewad
  • 343
  • 2
  • 9
0

Start your mySql with-

--sql_mode="NO_ZERO_DATE" --sql_mode="STRICT_ALL_TABLES"

then get your date using getString and use DateFormat for parsing. Then get it in ResultSet.

Helios
  • 851
  • 2
  • 7
  • 22