Hi community,

I have a problem with an application which makes use of a mysql database. I have a class which saves the fields of every record on the table. One of the columns is of type Datetime. Sometimes (!) I query this column and get results like with a timestamp, with a ".0" in the end. After some time on solving the problem I gave up and changed my code, so that it controls for that:

String date=result.getString("my_date");
		if(date.endsWith(".0")){
		this.myDate = StringUtils.sqlTimeStampFormat.parse(result.getString("my_date").replace(".0", ""));
		System.out.println("item" + this.id + "date" + this.myDate);
		}else{
			this.myDate = StringUtils.sqlTimeStampFormat.parse(result.getString("my_date"));
			
		}

But I still get the same exception:

Exception in thread "Thread-14" java.lang.NumberFormatException: multiple points
	at sun.misc.FloatingDecimal.readJavaFormatString(Unknown Source)
	at java.lang.Double.parseDouble(Unknown Source)
	at java.text.DigitList.getDouble(Unknown Source)
	at java.text.DecimalFormat.parse(Unknown Source)
	at java.text.SimpleDateFormat.subParse(Unknown Source)
	at java.text.SimpleDateFormat.parse(Unknown Source)
	at java.text.DateFormat.parse(Unknown Source)
	at org.et.bean.NewsItem.<init>(NewsItem.java:74)
	...

But when I inspect the part

StringUtils.sqlTimeStampFormat.parse(result.getString("my_date").replace(".0", ""))

during debugging, eclipse is showing me the right date for the string.

Does anybody have a pointer why this happens and how I could solve this problem?

All the best,
konrad

Recommended Answers

All 5 Replies

Why not just use getDate (for only a date) or getTimestamp for an actual timestamp?

Thanks for your answers. I was using a dateformat, because my sql table has the field as a datetime and not as timestamp. So I though I solve it with this dateformat snippet, since there is no getDateTime() in ResultSet.

And the problem described in the stackoverflow thread is exactly the one I have. Thank you very much for the good pointer!

Thanks for your answers. I was using a dateformat, because my sql table has the field as a datetime and not as timestamp. So I though I solve it with this dateformat snippet, since there is no getDateTime() in ResultSet.

And? You can still use get and set Timestamp on a DateTime field and the DB will still display the proper format when querying, so where's the problem with using the proper get and set calls?

Yes,getDate() and getTimestamp() can get datetime field

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.