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();
}
}
}
}
}
本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。