package mypackage;
import java.lang.reflect.Field;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class JDBCUtils {
private final String USERNAME = "root";
private final String PWD = "admin";
private final String DRIVER = "com.mysql.jdbc.Driver";
private Connection connection;
private java.sql.PreparedStatement preparedStatement;
private ResultSet resultset;
private String URL = "jdbc:mysql://localhost:3306/mydb";
public JDBCUtils() {
try {
Class.forName(DRIVER);
System.out.println("注冊驅動成功");
} catch (Exception e) {
// TODO: handle exception
}
}
// 定義獲得數據庫的鏈接
public Connection getConnection() {
try {
connection = DriverManager.getConnection(URL, USERNAME, PWD);
} catch (Exception e) {
// TODO: handle exception
}
return connection;
}
/**
*
* @param sql
* @param params
* @return
* @throws SQLException
*/
public boolean updateByPrepareStatement(String sql, List