gpt4 book ai didi

java - 我的程序中是否需要 Stmt.close()

转载 作者:行者123 更新时间:2023-12-02 00:49:10 26 4
gpt4 key购买 nike

我想知道

1.java中语句关闭的目的

2.如果我没有在程序中提供 stmt.close() 会发生什么

try{        
Statement DelQTY=OPConnect.createStatement();
Statement DelPMQTY=OPConnect.createStatement();
Statement DelPReq = OPConnect.createStatement();
Statement DelPro=OPConnect.createStatement();
Statement DelPPro=OPConnect.createStatement();
String DelSql="DELETE FROM ITEM_REQUIRES_MAT WHERE ITEM_NO=6364;
String DelPM="DELETE FROM PROGRAM_MATERIAL WHERE ITEM_NO=6364;
String DelPReqPro="DELETE FROM PROGRAM_REQ_PRODUCE_MAT WHERE ITEM_NO=6364;
String DelProcess="DELETE FROM PROCESS_TRANSFORMS_MAT WHERE ITEM_NO=6364;
String DelPProcess="DELETE FROM PROGRAM_PROCESS_TRANSFORMS_MAT WHERE ITEM_NO=6364;
DelPReq.executeUpdate(DelPReqPro);
DelQTY.executeUpdate(DelSql);
DelPMQTY.executeUpdate(DelPM);
DelPro.executeUpdate(DelProcess);
DelPPro.executeUpdate(DelPProcess);
DelQTY.close();
DelPMQTY.close();
DelPReq.close();
DelPro.close();
OPConnect.close();
}

这是我的示例代码,我错过了 DelPPro.close() 捕获(SQLException e) { e.printStackTrace(); }

最佳答案

Releases this Statement object's database and JDBC resources immediately instead of waiting for this to happen when it is automatically closed. It is generally good practice to release resources as soon as you are finished with them to avoid tying up database resources. Calling the method close on a Statement object that is already closed has no effect.

Note: A Statement object is automatically closed when it is garbage collected. When a Statement object is closed, its current ResultSet object, if one exists, is also closed.

Document

关于java - 我的程序中是否需要 Stmt.close(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3930600/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com