[Java] 日期处理 01 SimpleDataFormat 学习
2014-01-15 12:59
681 查看
SimpleDataFormat Learning.
import java.sql.*; import java.text.SimpleDateFormat; public class TestDate { public static void main(String[] args) { Connection conn = null; Statement stmt = null; ResultSet rs = null; try { Class.forName("com.mysql.jdbc.Driver"); conn = DriverManager .getConnection("jdbc:mysql://localhost/bbs?user=root&password=root"); stmt = conn.createStatement(); rs = stmt.executeQuery("select pdate from article"); while (rs.next()) { Date d = rs.getDate("pdate"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日"); // 重点在于自学的过程 System.out.println(sdf.format(d)); } } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException ex) { // handle any errors System.out.println("SQLException: " + ex.getMessage()); System.out.println("SQLState: " + ex.getSQLState()); System.out.println("VendorError: " + ex.getErrorCode()); } finally { try { if(rs != null) { rs.close(); rs = null; } if(stmt != null) { stmt.close(); stmt = null; } if(conn != null) { conn.close(); conn = null; } } catch (SQLException e) { e.printStackTrace(); } } } }
相关文章推荐
- Java学习提要——日期处理类
- [Java] 日期处理 01 SimpleDataFormat 学习
- 学习Java中的日期和时间处理及Java日历小程序的编写
- 0000006_java学习之路_JAVA日期处理
- java入门、java学习:java日期格式处理类,《上》
- java学习初探十一之日期处理
- Java学习之处理流中的转换流--2015-03-02
- Java for Web学习笔记(七十):Service和Repository(5)回调处理Consumer
- java学习-【转】java UncaughtExceptionHandler 处理线程意外中止
- java学习笔记——日期操作类(date,calendar等)
- JAVA处理日期时间常用方法
- 【Java学习笔记】48:盒内组件的支撑和ActionEvent事件处理
- Java的中文处理学习笔记:Hello Unicode
- java处理日期时间 相加减大全
- Java---日期处理(Date、Calendar、DateFormat)
- 如何在Java 8中愉快地处理日期和时间
- Java中关于日期的处理
- java日期处理(四)
- java -日期-Calendar 日期,天数,简单处理
- Java异常处理学习心得