Databases| SQL| MySQL| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Mysql Date To Java Date 
 

Mysql Date To Java Date retrieve the records from Mysql and display the date in java.

 

Mysql Date To Java Date

                         

Mysql Date To Java Date retrieve the records from Mysql and display the date in java.

Understand with Example

The Tutorial illustrate an example from 'Mysql Date To Java Date'. To understand and grasp the example we create a table 'mysql datetable', insert the records and display the records  from 'mysqldatetable' in java.

This Example display date from mysql in java:

select * from mysqldatetable:

 

 

 

+------------+------------+---------------------+
| time_field | date_field | date_time_field |
+------------+------------+---------------------+
| 12:20:10 | 2009-03-01 | 2009-01-03 12:20:10 |
+------------+------------+---------------------+

 Source Code :

import java.sql.*;
public class DateToJava {
public static void main(String args[]) {
ResultSet rs = null;
Connection con = null;
Statement stmt = null;
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/user_register","root","root");
stmt = con.createStatement();
rs = stmt.executeQuery("select time_field, date_field, date_time_field from mysqldatetable");
while (rs.next()) {
java.sql.Time mysqlTime = rs.getTime(1);
java.sql.Date mysqlDate = rs.getDate(2);
java.sql.Timestamp mysqlTimestamp = rs.getTimestamp(3);
System.out.println("mysqlTime=" + mysqlTime);
System.out.println("mysqlDate=" + mysqlDate);
System.out.println("mysqlTimestamp=" + mysqlTimestamp);

java.util.Date timeConverter = new java.util.Date(mysqlTime.getTime());
java.util.Date dateConverter = new java.util.Date(mysqlDate.getTime());
System.out.println("Standard Date");
System.out.println(timeConverter);
System.out.println(dateConverter);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
rs.close();
stmt.close();
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}

Output :

mysqlTime=12:20:10
mysqlDate=2009-03-01
mysqlTimestamp=2009-01-03 12:20:10.0
Standard Date
Thu Jan 01 12:20:10 GMT+05:30 1970
Sun Mar 01 00:00:00 GMT+05:30 2009

                         

» View all related tutorials
Related Tags: sql mysql c orm form time make format display value this create for ie example values exam e it mms

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.