MySQL工具包
package JdbcUtil;
//import java.io.IOException;
//import java.io.InputStream;
import java.sql.*;
import java.util.Properties;
public class JdbcUtil {
private static String driver = "com.mysql.cj.jdbc.Driver";
private static String url = "jdbc:mysql://localhost:3306/sqltestdb?useSSL=false&&serverTimezone=UTC";
private static String user = "root";
private static String password = "0203";
private static Properties properties = new Properties();
Connection connection = null;
static {
try {
/* InputStream inputStream = Thread.currentThread().getContextClassLoader().
getResourceAsStream("db.properties");
properties.load(inputStream);*/
Class.forName(driver);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
public static Connection getConnection() {
try {
return DriverManager.getConnection(url, user, password);
} catch (SQLException e) {
e.printStackTrace();
}
return null;
}
public static void close(Connection connection, Statement statement, ResultSet resultSet) {
try {
if (resultSet != null) {
resultSet.close();
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (statement != null) {
statement.close();
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (connection != null) {
connection.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}