In a java application what would a good compromise in terms of extracing and inputting date information with a MySQL database using a mix of datetimes and timestamps?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In Java side, the date is usually represented by the (poorly designed, but that aside)
java.util.Date. It is basically backed by the Epoch time in flavor of along, also known as a timestamp. It contains information about both the date and time parts. In Java, the precision is in milliseconds.In SQL side, there are several standard date and time types,
DATE,TIMEandTIMESTAMP(at some DB’s also calledDATETIME), which are represented in JDBC asjava.sql.Date,java.sql.Timeandjava.sql.Timestamp, all subclasses ofjava.util.Date. The precision is DB dependent, often in milliseconds like Java, but it can also be in seconds.In contrary to
java.util.Date, thejava.sql.Datecontains only information about the date part (year, month, day). TheTimecontains only information about the time part (hours, minutes, seconds) and theTimestampcontains information about the both parts, like asjava.util.Datedoes.The normal practice to store a timestamp in the DB (thus,
java.util.Datein Java side andjava.sql.Timestampin JDBC side) is to usePreparedStatement#setTimestamp().The normal practice to obtain a timestamp from the DB is to use
ResultSet#getTimestamp().