0

Hi, iam new to jsp. actually my problem is with the format of date and time.Datea nad time stored in database are in hh:mm:ss format. but when i am displaying reports, nanoseconds are displaying. please give reason for this.

2
Contributors
9
Replies
19
Views
4 Years
Discussion Span
Last Post by radhakrishna.p
0

hai Neha290791,

could you post the code how you get the date data from database?

so that we try to give a way to solution

0

try{

    con=java.sql.DriverManager.getConnection("jdbc:mysql://localhost/aces_incident_management","root","wipro@123");
    stmt=con.createStatement();
    try {

    String query = "select incident_id, assignee_name, open_time from aces_incident_details where incident_id='"+etno+"' and deletion_status is null";  
        rs =stmt.executeQuery(query);
    } catch (java.sql.SQLException e) {
        out.println(e);
    } 

         if(rs.next()){
         %>
         <table border="1" cellspacing="0" cellpadding="0" width="950" height="23" align="center" >
              <tr>
                <th align="center" width="100">
                <font face = "VERDANA" color = "maroon" size = "2">Problem ID</font></th>
                <font face = "VERDANA" color = "maroon" size = "2">Assignee Name</font></th>
                <th align="center">
                <font face = "VERDANA" color = "maroon" size = "2">Open Time</font></th>
              </tr>
                <TR> 
                <TD><center>
                <font face = "VERDANA" color = "maroon" size = "2"><%= rs.getString(1)%></center></font></TD>
                <TD><center>
                <font face = "VERDANA" color = "maroon" size = "2"><%= rs.getString(2)%></center></font></TD>
                <TD><center>
                <font face = "VERDANA" color = "maroon" size = "2"><%= rs.getString(3)%></center></font></TD>

            </TR>

            </table><br><%
            rs.close();
            stmt.close();
            con.close();
0

@Neha290791,

could you post structure of the table?

but you are talking about time column and you are displaying/getting that data by using rs.getString() instead of using rs.getDate()

so i need data type of open_time column of your table.
[modified]

Edited by radhakrishna.p: giving proper reason for solution

0

yeah Neha290791,

if the data type is of date or datetime type

try to do as follows

first get the column value

your_date = rs.getDate("open_time");

then use SimpleDateFormat class to display the time as you like (as follows)

SimpleDateFormat formatter = new SimpleDateFormat("your_format_here");
formatter.format(your_date);  // returns string then display it whareever you want 

check it once and let me know the status

happy coding

0

hai,

java.sql.Time or java.sql.Date both are perfect(as of my knowledge)

but in this case you go for java.sql.Time
try like this

java.sql.Time t = rs.getTime();
SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:ss");
sdf.format(t)  // return string  

check it once

note : pls post output too incase if you haven't got the output as you expected

[modified]

Edited by radhakrishna.p: clarity on the solution

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.