BaseDao
package dao; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; public class BaseDao { private static String CLASS_NAME = "com.mysql.jdbc.Driver"; private static String URL = "jdbc:mysql://127.0.0.1/frsys"; private static String USER_NAME = "root"; private static String USER_PWD = "root"; protected static Connection m_conn = null; protected static PreparedStatement m_ps = null; protected static ResultSet m_ds = null; protected static Connection getConn() { try { Class.forName(CLASS_NAME); m_conn = DriverManager.getConnection(URL, USER_NAME, USER_PWD); } catch (Exception e) { e.printStackTrace(); } return m_conn; } protected static void closeConn() { try { if (m_ds != null) { m_ds.close(); m_ds = null; } if (m_ps != null) { m_ps.close(); m_ps = null; } if (m_conn != null) { m_conn.close(); m_conn = null; } } catch (SQLException e) { e.printStackTrace(); } } public static void main(String[] args) { getConn(); System.out.println(m_conn); closeConn(); System.out.println(m_conn); } }