- This topic has 3 replies, 1 voice, and was last updated 19 years, 12 months ago by doug bloomfield.
-
AuthorPosts
-
doug bloomfieldParticipantI’ve just installed Eclipse 3.1 and MyEclipse 3.8.4 so that I could use the new features added in Java 1.5. After installing those items, all of my Junit tests which involve getting any DateTime/TimeStamp value from the MySql database fail. The date I get back is correct, except it has ‘.0’ appended to the end. i.e. 2004-12-16 12:12:12 becomes 2004-12-16 12:12:12.0 in the ResultSet object.
I believe I am using MySql 1.4.6, but I don’t think that is the problem. I haven’t changed the MySql installation.
This class will reproduce the problem on my machine:
public class DateTest{
public static void main(String[] args){
Connection conn = null;
Statement stmt = null;
try{
Class.forName(“com.mysql.jdbc.Driver”);
conn = DriverManager.getConnection(“yourConnectionStringHere“);
conn.setAutoCommit(true);
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
ResultSet rs = stmt.executeQuery(“SELECT yourDateField FROM yourTable WHERE yourPK = 1″);
while(rs.next()){
String test = rs.getString(1);
String putYourBreakPointHere = “”;
}
}
catch(ClassNotFoundException e){e.printStackTrace();}
catch(SQLException e){e.printStackTrace();}
}
}Set a watch on rs.getString(1), and if the field is a DateTime or a TimeStamp, you’ll get your date with .0 appended.
I’d appreciate any help with this.
doug bloomfieldParticipantBy the way, I’m using MySql 1.4.7
doug bloomfieldParticipantI found my problem. Here’s an FYI for anyone who’s curious.
I remembered that I had also recently changed my JDBC connector drivers for MySql, and figured that it was more likely the trouble, so I replaced the file I had recently put into my JRE System library (mysql-connector-java-3.1.6-bin.jar) with the one I had previously removed but kept (mysql-connector-java-3.0.15-ga-bin.jar). It now works fine. I have no idea why the newer connector was causing the ResultSet to retrieve the dates wrong, but it was.
Anyhow, in case you have similar difficulties,
mysql-connector-java-3.1.6-bin.jar = BAD!!
mysql-connector-java-3.0.15-ga-bin.jar = GOOD.
doug bloomfieldParticipantAnother last note on this…
This connector also causes any YEAR types you may have in your DB to come back as 2004-01-01 instead of just the four digit 2004, so if your code is relying on a specific format for these types, BEWARE…
In case you’re wondering, MySql doesn’t store tenths of a second, nor does it store the year with anything but the four digit year. I tried both.
I tried the newer connector on my coworkers machine, who still has an older version of Eclipse and MyEclipse, and it produces the same results. I’ve also tried downloading a new copy of the connector, but it didn’t change the behavior.
-
AuthorPosts