Date operation
package jdbc.test;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Date;
public class DateManapulate {
public static int writeDate(Date date) throws SQLException, ClassNotFoundException{
String sql = "insert into tabe_date_text_blob (birthday) values (?)" ;
PreparedStatement ps = JdbcMySqlUtil.getInstance().getPrepareStatement(sql);
ps.setDate(1, new java.sql.Date(new java.util.Date().getTime()));
int x = ps.executeUpdate() ;
JdbcMySqlUtil.free(null, ps, ps.getConnection());
return x ;
}
public static Date readDate() throws SQLException, ClassNotFoundException{
String sql ="select birthday from tabe_date_text_blob where id = 1" ;
Statement st = JdbcMySqlUtil.getInstance().getStatement();
ResultSet rs = st.executeQuery(sql);
Date d ;
while(rs.next())
d= rs.getDate(1); //java.sql.Date is a sub class of java.util.Date
JdbcMySqlUtil.free(rs, st, st.getConnection());
return null ;
}
}