12.17-javaweb复习

复习内容:做了一些练习题复习sql连接关闭


public class DButils {
static public Connection connection;
static public String driver = "com.mysql.cj.jdbc.Driver";
static public String url = "jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC";
static public String user = "root";
static public String password = "wang@@ke123";

static public void Connection_close(Connection connection, PreparedStatement preparedStatement) {
try {
if (connection != null)
connection.close();
if (preparedStatement != null)
preparedStatement.close();
} catch (SQLException throwables) {
throwables.printStackTrace();
}
}

static public void Connection_close(Connection connection, PreparedStatement preparedStatement, ResultSet resultSet) {
try {
if (resultSet != null)
resultSet.close();
if (preparedStatement != null)
preparedStatement.close();
if (connection != null)
connection.close();
} catch (SQLException throwables) {
throwables.printStackTrace();
}
}

static public Connection GetConnnection() throws ClassNotFoundException, SQLException {
Class.forName(driver);
connection= DriverManager.getConnection(url,user,password);
return connection;
}
}
posted @ 2020-12-17 14:48  While!true  阅读(87)  评论(0编辑  收藏  举报