I created the following table on a MySQL DataBase:
CREATE TABLE DATES(
DT DATETIME,
TS TIMESTAMP,
);
And inserted the following data into the DATES:
INSERT INTO DATES(DT, TS) VALUES(NOW(), NOW());
So when I do the following query:
SELECT * FROM DATES;
The result is the following:
_______DT________|_______TS_________
2017-11-26 12:16:34_|_2017-11-26 12:16:34
Which is correct, each register holds the current date and time of the moment I inserted the data into DATES.
However, when I try to display those values using the following query in Java:
try{
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/MYDB","root","pswrd");
Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
ResultSet srs = stmt.executeQuery("SELECT * FROM DATES");
}
catch(Exception e){
e.printStackTrace();
JOptionPane.showMessageDialog(null, "Error.");
}
I get the following output:
____DT____|____TS____
2017-11-26_|_2017-11-26
That is, the query shows only the incomplete values, as it's only returning the values of the dates stored but not the times.
Is there any way to display both the date & time, as opposed to just the date?
Also, I'm using a JTable to display those values as I cannot find a way to store them in a variable and display them with:
JOptionPane.showMessageDialog(null, "Date & Time: " + <<I want the values here>>);
Any help would be greatly appreciated. Thanks in advance!