The JDBC Date processing usage is detailed and can be used as a standard class package JDBC to connect JDBC;
import java.sql.Connection;
import java.sql.Date;
import Java.sql.ResultSet;
import java.sql.SQLException;
import Java.sql.DriverManager;
import java.sql.Statement;
import Java.sql.Time;
import Java.sql.Timestamp;
import Java.text.SimpleDateFormat;
import Java.util.Calendar;
/** *//**
*
* @author Oakertree
*
*/
public class Testjdbcdate {
public static void Main (string[] args) {
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
try {
class.forname ("Com.mysql.jdbc.Driver");
//New Com.mysql.jdbc.Driver ();
con = drivermanager.getconnection ("Jdbc:mysql://localhost:3307/test", "root", "Admini");
stmt = Con.createstatement ();
rs = stmt.executequery ("SELECT * from time");
while (Rs.next ()) {
/**//*
Date D = rs.getdate ("date");
//SimpleDateFormat SDF = new SimpleDateFormat ("YYYY year mm month DD Day");
System.out.println (Sdf.format (d));
*/
/**//*
time t = rs.gettime ("Time");
SimpleDateFormat sdf = new SimpleDateFormat ("hh when mm minute ss seconds");
System.out.println (Sdf.format (t));
*/
Date d = rs.getdate ("datetime");
time t = rs.gettime ("datetime");
SimpleDateFormat sdfdate = new SimpleDateFormat ("YYYY year mm month DD Day");
SimpleDateFormat sdftime = new SimpleDateFormat ("hh when mm minute ss seconds");
System.out.println (Sdfdate.format (d) + Sdftime.format (t));
/**//*
Timestamp dt = Rs.gettimestamp ("datetime");
SimpleDateFormat sdf = new SimpleDateFormat ("yyyy mm month DD Day hh when mm minute ss seconds");
System.out.println (Sdf.format (DT));
*/
//Get the month
of the date
/**//*
Calendar C = calendar.getinstance ();
C.settime (d);
System.out.println (C.get (calendar.month));
*/
}
} catch (ClassNotFoundException e) {
E.printstacktrace ();
catch (SQLException e) {
E.printstacktrace ();
} finally {
try {
if (rs!= null) {
Rs.close ();
rs = null;
}
if (stmt!= null) {
Stmt.close ();
stmt = null;
}
if (con!= null) {
Con.close ();
con = null;
}
} catch (SQLException e) {
E.printstacktrace ();
}
}
}
}
/**//*
+----------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+----------+------+-----+---------+-------+
| Date | Date | YES | | NULL | |
| Time | Time | YES | | NULL | |
| datetime | datetime | YES | | NULL | |
+----------+----------+------+-----+---------+-------+
*/