📄 connectionmanager.java
字号:
package manager;
import java.sql.*;
public class ConnectionManager {
private static String DRIVER="com.microsoft.jdbc.sqlserver.SQLServerDriver";
private static String URL = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=news";
/**
* getConnction
* @param none
*/
public static Connection getConnction(){
Connection con = null;
try{
Class.forName(DRIVER);
con = DriverManager.getConnection(URL, "sa", "");
}catch(Exception e){
e.printStackTrace();
}
return con;
}
/**
* closeConnection
* @param con Connection
*/
public static void closeConnection(Connection con){
try{
if(con != null && (!con.isClosed())){
con.close();
}
}catch(Exception e){
e.printStackTrace();
}
}
/**
* closeStatement
* @param stmt PreparedStatement
*/
public static void closeStatement(PreparedStatement stmt) {
try {
if (stmt != null) {
stmt.close(); stmt = null;
}
} catch (SQLException e) {
e.printStackTrace();
}
}
/**
* closeResultSet
* @param rs ResultSet
*/
public static void closeResultSet(ResultSet rs) {
try {
if (rs != null) {
rs.close(); rs = null;
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -