还是说仅仅执行 sql 的工具,mysql 的会话是是在 sql 执行的过程中创建的
另外 Statement 的 close 有什么用?不关闭会有问题吗
1
snappyone 2019-01-19 21:46:18 +08:00
Connection 才是你所说的会话
Statement 是会话中执行的一条语句 close 的作用就是释放资源,不关闭会导致内存泄漏 |
2
noble4cc OP @snappyone 但是 Statement 不会被 vm 回收不就不会内存泄露了?
另外 mysql 中的 connect 和 session 是两个概念,一个 connect 可能会有好几个 session 但是到了 jdbc 这里就合二为一了? |
3
snappyone 2019-01-21 08:05:50 +08:00 via Android
@noble4cc 连接和会话的区别我又查了下,感觉一个偏物理层一个偏应用层,但是总体基本一个意思。close 内存泄露这个可以直接看 jdk 的解释,愿意是 release resources as soon as possible,不释放是有可能造成问题的,具体应该应该跟垃圾回收机制有关
|
4
wleexi 2019-01-21 09:34:26 +08:00
* A Connection object represents a connection to a data source via a JDBC technology-enabled driver. The data source can be a DBMS, a legacy file system, or some other source of data with a corresponding JDBC driver. A single application using the JDBC API may maintain multiple connections. These connections may access multiple data sources, or they may all access a single data source.
From the JDBC driver perspective, a Connection object represents a client session. It has associated state information such as user ID, a set of SQL statements and result sets being used in that session, and what transaction semantics are in effect. * The Statement interface defines methods for executing SQL statements that do not contain parameter markers. The PreparedStatement interface adds methods for setting input parameters, and the CallableStatement interface adds methods for retrieving output parameter values returned from stored procedures. * An application calls the method Connection.close() to indicate that it has finished using a connection. All Statement objects created from a given Connection object will be closed when the close method for the Connection object is called. jsr221 |