81,094
社区成员
发帖
与我相关
我的任务
分享
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();
}
}
}
}
}