日期:2014-05-20 浏览次数:20749 次
package com.cn.zjjt.util; import java.sql.Connection; import java.sql.DriverManager; public final class JdbcUtil { public static final String DB_DRIVER="org.gjt.mm.mysql.Driver"; public static final String DB_URL="jdbc:mysql://localhost/zjjt"; public static final String DB_USERNAME="root"; public static final String DB_PASSWORD="root"; Connection conn; private JdbcUtil(){ } static { try { Class.forName(DB_DRIVER); } catch (Exception e) { e.printStackTrace(); System.out.println(e.toString()); } } public static Connection getConnection() throws Exception //返回Connection { return DriverManager.getConnection(DB_URL,DB_USERNAME,DB_PASSWORD); } public void dbClose() //关闭数据库连接 { try { conn.close(); } catch (Exception e) { e.printStackTrace(); System.out.println(e.toString()); } } }