1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| package Utils;
import java.sql.*;
public class JDBCUtils { public static Connection getConnection() throws SQLException,ClassNotFoundException{ Class.forName("com.mysql.cj.jdbc.Driver"); String url = "jdbc:mysql://127.0.0.1:3306/bloguser?serverTimezone=UTC&useUnicode=true&characterEncoding=utf8"; String username = "root"; String password = "skyang9";
Connection conn = DriverManager.getConnection(url,username,password); return conn; }
public static void release(PreparedStatement stmt , Connection conn){ if(stmt != null){ try{ stmt.close(); }catch(SQLException e){ e.printStackTrace(); } } if(conn != null){ try{ conn.close(); }catch(SQLException e){ e.printStackTrace(); } } }
public static void release(ResultSet rs , PreparedStatement stmt , Connection conn){ if(rs != null){ try{ rs.close(); }catch(SQLException e){ e.printStackTrace(); } } release(stmt,conn); } }
|