Hi,
And I find that there are different modes you can choose when you create a
statement in mysql-jdbc.
If you choose the KEEP_CURRENT_RESULT mode, it can hold more than one results,
as the following source code shows:
case java.sql.Statement.KEEP_CURRENT_RESULT:
if (!this.dontTrackOpenResources.getValue()) {
this.openResults.add(this.results);
}
this.results.clearNextResultset(); // nobody besides us should
// ever need this value...
break;
> -----原始邮件-----
> 发件人: "田原" <[email protected]>
> 发送时间: 2019-11-06 19:00:28 (星期三)
> 收件人: [email protected]
> 抄送:
> 主题: Re: Re: (IOTDB-291) Statement close operation may cause the whole
> connection's resource to be released
>
> Hi,
>
> Will this example run well? Or it will throw an exception because you have
> another stmt.executeQuery() in the while-loop and the rs will be closed?
>
> I've checked the source code of mysql-jdbc, it seems that it will really
> close all the opened ResultSets in execute function. However, I think one
> statement hold for more than one ResultSets is ok. It is like that one
> connection can have multiple statements. It is just implementation difference.
>
>
> > -----原始邮件-----
> > 发件人: "″ 等灯.等灯`" <[email protected]>
> > 发送时间: 2019-11-06 18:52:38 (星期三)
> > 收件人: dev <[email protected]>
> > 抄送:
> > 主题: Re: (IOTDB-291) Statement close operation may cause the whole
> > connection's resource to be released
> >
> > hi tiany,
> > i am so sorry , my english is poor!
> > Connection conn = null;
> > Statement stmt = null;
> > conn = .......;
> > stmt = conm.createStatement(xxxxxx);
> > ResultSet rs = stmt.executeQuery(sql1);
> > while(rs.next()){
> > str = rs.getString(xxxxx);
> > ResultSet rs1 = stmt. stmt.executeQuery(\"select * from
> > anyTable where any=str\");
> > }
> >
> >
> > it's true?
> >
> > 发自我的iPhone
> >
> >
> > ------------------ Original ------------------
> > From: 田原 <[email protected]>
> > Date: Wed,Nov 6,2019 6:34 PM
> > To: dev <[email protected]>
> > Subject: Re: (IOTDB-291) Statement close operation may cause the whole
> > connection's resource to be released
> >
> >
> >
> > Hi, Liu
> >
> > You mean at the same time, one statement can only hold one ResultSet in
> > mysql-jdbc?
> >
> >
> > > -----原始邮件-----
> > > 发件人: "″ 等灯.等灯`" <[email protected]>
> > > 发送时间: 2019-11-06 17:41:28 (星期三)
> > > 收件人: dev <[email protected]>
> > > 抄送:
> > > 主题: 回复: (IOTDB-291) Statement close operation may cause the whole
> > connection's resource to be released
> > >
> > > hi&nbsp;tiany,&nbsp;
> > > in&nbsp;cluster, how to save the&nbsp;statementId Map, and how
> > to releases the resources corresponding of&nbsp;queryIds ,&nbsp;
> > > i see mysql jdbc when call execute(sql) method , it will
> > to&nbsp;implicitlyCloseAllOpenResults ,why not&nbsp;refer to this?
> > > you want the client nested call ?
> > > ------------------&nbsp;原始邮件&nbsp;------------------
> > > 发件人:&nbsp;"田原"<[email protected]&gt;;
> > > 发送时间:&nbsp;2019年11月6日(星期三) 下午5:13
> > > 收件人:&nbsp;"dev"<[email protected]&gt;;
> > >
> > > 主题:&nbsp;Re: (IOTDB-291) Statement close operation may cause the
> > whole connection's resource to be released
> > >
> > >
> > >
> > > Hi,
> > >
> > > I have solved the issued by maintaining a ThreadLocal<Map<Long,
> > Set<Long&gt;&gt;&gt; in the TSServiceImpl which is a map
> > (statementId -&gt; all queryIds in that statement).
> > >
> > > Every time the statement is closed, all the queryIds in that map
> > should also be closed.
> > > However, when a ResultSet is closed, it only releases the resources
> > corresponding to that queryId.
> > > When the connection is closed, the function closeSession() is invoked,
> > it will release all the resource saved in that session thread.
> > >
> > > The PR link is https://github.com/apache/incubator-iotdb/pull/526.
> > >
> > >
> > > &gt; -----原始邮件-----
> > > &gt; 发件人: "Yuan Tian (Jira)" <[email protected]&gt;
> > > &gt; 发送时间: 2019-11-05 22:53:00 (星期二)
> > > &gt; 收件人: [email protected]
> > > &gt; 抄送:
> > > &gt; 主题: [jira] [Created] (IOTDB-291) Statement close operation
> > may cause the whole connection's resource to be released
> > > &gt;
> > > &gt; Yuan Tian created IOTDB-291:
> > > &gt; -------------------------------
> > > &gt;
> > >
> > &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
> > Summary: Statement close operation may cause the whole connection's
> > resource to be released
> > >
> > &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
> > Key: IOTDB-291
> > >
> > &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
> > URL: https://issues.apache.org/jira/browse/IOTDB-291
> > >
> > &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
> > Project: Apache IoTDB
> > >
> > &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
> > Issue Type: Bug
> > >
> > &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
> > Reporter: Yuan Tian
> > > &gt;
> > > &gt;
> > > &gt; The function closeClientOperation() in IoTDBStatement.java
> > invokes the function closeOperation(TSCloseOperationReq) in TSServiceImpl.
> > > &gt; Because the queryId field in TSCloseOperationReq is set to be
> > -1L, the releaseQueryResource&nbsp; function will release all the
> > resources&nbsp; in that connection.
> > > &gt;
> > > &gt; {code:java}
> > > &gt;&nbsp;&nbsp; private void closeClientOperation()
> > throws SQLException {
> > > &gt;&nbsp;&nbsp;&nbsp;&nbsp; try {
> > > &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
> > if (operationHandle != null) {
> > >
> > &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
> > TSCloseOperationReq closeReq = new TSCloseOperationReq(operationHandle,
> > -1);
> > >
> > &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
> > closeReq.setStmtId(stmtId);
> > >
> > &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
> > TSStatus closeResp = client.closeOperation(closeReq);
> > >
> > &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
> > RpcUtils.verifySuccess(closeResp);
> > > &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
> > > &gt;&nbsp;&nbsp;&nbsp;&nbsp; } catch (Exception e)
> > {
> > > &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
> > throw new SQLException("Error occurs when closing statement.", e);
> > > &gt;&nbsp;&nbsp;&nbsp;&nbsp; }
> > > &gt;&nbsp;&nbsp; }
> > > &gt; {code}
> > > &gt;
> > > &gt; {code:java}
> > > &gt;&nbsp;&nbsp; private void
> > releaseQueryResource(TSCloseOperationReq req) throws StorageEngineException
> > {
> > > &gt;&nbsp;&nbsp;&nbsp;&nbsp; Map<Long,
> > QueryContext&gt; contextMap = contextMapLocal.get();
> > > &gt;&nbsp;&nbsp;&nbsp;&nbsp; if (contextMap ==
> > null) {
> > > &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
> > return;
> > > &gt;&nbsp;&nbsp;&nbsp;&nbsp; }
> > > &gt;&nbsp;&nbsp;&nbsp;&nbsp; if (req == null ||
> > req.queryId == -1) {
> > > &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
> > // end query for all the query tokens created by current thread
> > > &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
> > for (QueryContext context : contextMap.values()) {
> > >
> > &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
> > QueryResourceManager.getInstance().endQueryForGivenJob(context.getJobId());
> > > &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
> > > &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
> > contextMapLocal.set(new HashMap<&gt;());
> > > &gt;&nbsp;&nbsp;&nbsp;&nbsp; } else {
> > > &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
> > QueryResourceManager.getInstance()
> > >
> > &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
> > .endQueryForGivenJob(contextMap.remove(req.queryId).getJobId());
> > > &gt;&nbsp;&nbsp;&nbsp;&nbsp; }
> > > &gt;&nbsp;&nbsp; }
> > > &gt; {code}
> > > &gt;
> > > &gt;
> > > &gt;
> > > &gt;
> > > &gt; --
> > > &gt; This message was sent by Atlassian Jira
> > > &gt; (v8.3.4#803005)