日期:2014-05-17 浏览次数:20913 次
public final class JdbcUtils { private static String driver="com.microsoft.sqlserver.jdbc.SQLServerDriver"; private static String url="jdbc:sqlserver://localhost:1433;DatabaseName=JspWebDb"; private static String user="sa"; private static String psw="12345"; private JdbcUtils(){} private static JdbcUtils instanse=new JdbcUtils(); public static JdbcUtils getInstanse() { return instanse; } static{ try{ Class.forName(driver); } catch(ClassNotFoundException e) { throw new ExceptionInInitializerError(e); } } public static Connection getConnection() throws SQLException { return DriverManager.getConnection(url,user,psw); } public static void free(ResultSet rs,Statement st,Connection conn) { if(rs!=null) try { rs.close(); } catch (SQLException e) { e.printStackTrace(); } finally { if(st!=null) try { st.close(); } catch (SQLException e) { e.printStackTrace(); } finally { if(conn!=null) try { conn.close(); } catch (SQLException e) { e.printStackTrace(); } } } } }