package com.dianlian.jdbc; import java.sql.Connection; import java.sql.DriverManager; import java.sql.Timestamp; /** * 數(shù)據(jù)庫操作工具類 * * Jul 30, 2013 * @author CevenCheng */ public class DBUtils { private static String URL = "jdbc:mysql://localhost:3306/DB?characterEncoding=utf-8"; private static String USER = "root"; private static String PASSWORD = "mysql"; /** * 獲取數(shù)據(jù)庫連接 * @return */ public static Connection getConnection() { try { Class.forName("com.mysql.jdbc.Driver"); return DriverManager.getConnection(URL, USER, PASSWORD); } catch (Exception e) { e.printStackTrace(); return null; } } public static void closeConnection(Connection conn) { try { if(conn != null) { conn.close(); } } catch (Exception e) { e.printStackTrace(); } } public static void main(String[] args) { String time = "2013-06-29 17:26:02.0"; System.out.println(Timestamp.valueOf(time)); } } |
|
來自: CevenCheng > 《常用工具》