jdbc

JDBCUtlis工具类

其实就是将,java连接mysql的方法进行封装,使得重复代码减少

连接和关闭都算是重复代码。

public class JDBCUtils {

    public static Connection getConnect() throws IOException, ClassNotFoundException, SQLException {
        //导入配置信息
        Properties properties = new Properties();
        properties.load(new FileInputStream("D:\\IDEA\\workspace\\mysql.properties"));
        String driver = properties.getProperty("driver");
        String url = properties.getProperty("url");
        String user = properties.getProperty("user");
        String password = properties.getProperty("password");

        Class.forName(driver);
        Connection connection = DriverManager.getConnection(url, user, password);

        return connection;
    }

    public static void closeConnect(ResultSet resultSet, Statement statement,Connection connection) throws SQLException {
        if(resultSet != null){
            resultSet.close();
        }
        if(statement != null){
            statement.close();
        }
        if(connection != null){
            connection.close();
    }
    }
}
url=jdbc:mysql://localhost:3306/sora?rewriteBatchedStatements=true
user=root
password=root
driver=com.mysql.cj.jdbc.Driver

事务

一个形象的例子就是,当年给人转账时,需要你的账户减少,别人账户增加。不能出现问题,只有一方增加或者减少。事务就是为了解决这样的问题。

批处理

为了提高效率,把一堆sql语句先存在一块。然后提交一堆语句,大概

posted @ 2022-03-05 15:09  xiaoovo  阅读(35)  评论(0)    收藏  举报