package nc.bs.mdm.plugin;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class JDBC_Connection {
public static Connection getConnection (String url,String username,String password,String Driver) throws SQLException,ClassNotFoundException{
Class.forName(Driver);
Connection conn=DriverManager.getConnection(url, username, password);
return conn;
}
public static Connection getConnection () throws SQLException,ClassNotFoundException{
Class.forName("com.mysql.jdbc.Driver");
String url="jdbc:mysql://localost:3306/xxx";
String username="root";
String password="123456";
Connection conn=DriverManager.getConnection(url, username, password);
return conn;
}
//关闭数据库连接,释放资源
public static void close(Statement stmt,Connection conn){
if(stmt!=null){
try{
stmt.close();
}catch(SQLException e){
e.printStackTrace();
}
stmt=null;
}
if(conn!=null){
try{
conn.close();
}catch(SQLException e){
e.printStackTrace();
}
conn=null;
}
}
public static void close(ResultSet rs,Statement stmt,Connection conn){
if(rs!=null){
try{
rs.close();
}catch(SQLException e){
e.printStackTrace();
}
rs=null;
}
release(stmt,conn);
}
}
JDBC连接工具类
最新推荐文章于 2023-10-03 23:17:26 发布