java操作JDBC之MySQL工具類
阿新 • • 發佈:2018-11-06
/** * JDBC之MySQL工具類 * * @author: Rodge * @time: 2018年10月4日 下午4:03:42 * @version: V1.0.0 */ public class JDBCUtilForMySQL { private static final String URL = "jdbc:mysql://localhost:3306/test"; private static final String USER = "root"; private static final String PASSWORD = "1234"; private static Connection conn = null; static { try { Class.forName("com.mysql.jdbc.Driver"); conn = DriverManager.getConnection(URL, USER, PASSWORD); } catch (Exception e) { e.printStackTrace(); } } /** * 獲取資料庫連線 * @return */ public static Connection getConnection () { return conn; } public static void main(String[] args) { System.out.println(JDBCUtilForMySQL.getConnection()); } }