
Hi. I have retrieved time from mysql database. its in th format hh:mm:ss. but i want to display only as hh:mm. wat to do?

Here is a jsp example that fetch the time from the database and display in different format.
<%@page import="java.sql.*"%>
<%@page import="java.util.*"%>
<%@page import="java.text.*"%>
<%
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root" );
Statement st=conn.createStatement();
ResultSet rs=st.executeQuery("select * from patient");
SimpleDateFormat sdf=new SimpleDateFormat("hh:mm");
while(rs.next()){
java.sql.Time dbSqlTime = rs.getTime("tob");
java.util.Date date = new java.util.Date(dbSqlTime.getTime());
out.println(sdf.format(date)+"<br>");
%>

Here is a jsp example that fetch the time from the database and display in different format.
<%@page import="java.sql.*"%>
<%@page import="java.util.*"%>
<%@page import="java.text.*"%>
<%
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root" );
Statement st=conn.createStatement();
ResultSet rs=st.executeQuery("select * from patient");
SimpleDateFormat sdf=new SimpleDateFormat("hh:mm");
while(rs.next()){
java.sql.Time dbSqlTime = rs.getTime("tob");
java.util.Date date = new java.util.Date(dbSqlTime.getTime());
out.println(sdf.format(date)+"<br>");
%>
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.