I am new to Java. I am retrieving my first column from database in a String Array which represents data as:
2014-09-01 10:00:00.000
Now I want to display only time as:
10:00:00
How to do it? My code to retrieve my Column is:
public String[] getChartTime() throws SQLException {
List < String > timeStr = new ArrayList < String > ();
String atime[] = null;
getConnection();
try {
con = getConnection();
String sql = "exec vcs_gauge @gauge_name=?,@first_rec_time=?,@last_rec_time=?";
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println("date is " + df.format(currentDate));
clstmt = con.prepareCall(sql);
clstmt.setString(1, "vs3_bag");
clstmt.setString(2, "2014-09-01 10:00:00");
clstmt.setString(3, "2014-09-01 11:00:00");
clstmt.execute();
rs = clstmt.getResultSet();
while (rs.next()) {
// Just get the value of the column, and add it to the list
timeStr.add(rs.getString(1));
}
} catch (Exception e) {
System.out.println("\nException in Bean in getDbTable(String code):" + e);
} finally {
closeConnection();
}
// I would return the list here, but let's convert it to an array
atime = timeStr.toArray(new String[timeStr.size()]);
for (String s: atime) {
System.out.println(s);
}
return atime;
}