jdbc 中每 create 一个 Statement 就是和数据库建立一个会话吗? - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
noble4cc
V2EX    Java

jdbc 中每 create 一个 Statement 就是和数据库建立一个会话吗?

  •  
  •   noble4cc 2019 年 1 月 19 日 2482 次点击
    这是一个创建于 2653 天前的主题,其中的信息可能已经有所发展或是发生改变。

    还是说仅仅执行 sql 的工具,mysql 的会话是是在 sql 执行的过程中创建的

    另外 Statement 的 close 有什么用?不关闭会有问题吗

    4 条回复    2019-01-21 09:34:26 +08:00
    snappyone
        1
    snappyone  
       2019 年 1 月 19 日
    Connection 才是你所说的会话
    Statement 是会话中执行的一条语句
    close 的作用就是释放资源,不关闭会导致内存泄漏
    noble4cc
        2
    noble4cc  
    OP
       2019 年 1 月 20 日
    @snappyone 但是 Statement 不会被 vm 回收不就不会内存泄露了?

    另外 mysql 中的 connect 和 session 是两个概念,一个 connect 可能会有好几个 session
    但是到了 jdbc 这里就合二为一了?
    snappyone
        3
    snappyone  
       2019 年 1 月 21 日 via Android
    @noble4cc 连接和会话的区别我又查了下,感觉一个偏物理层一个偏应用层,但是总体基本一个意思。close 内存泄露这个可以直接看 jdk 的解释,愿意是 release resources as soon as possible,不释放是有可能造成问题的,具体应该应该跟垃圾回收机制有关
    wleexi
        4
    wleexi  
       2019 年 1 月 21 日
    * 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
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     1683 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 32ms UTC 16:19 PVG 00:19 LAX 09:19 JFK 12:19
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86