how to remain a TObject after the corresponding TFile is closed

当一个TFile 被关闭时,在这个文件打开至结束之间产生的任何类,默认都是delete的。其用意相当于,TFile相当于一个目录,当打开这个目录的时候,里面的任何东西都是可以看得到的,但当关闭了这个目录,其中的任何东西都在内存中被清除。这是一个保持文件使用过程中保持内存清洁的做法。

但是有的时候,我们可能会连续打开多个文件,并在每一个文件中提取一个TObject。而在这些文件都被关闭后,再使用它们。这就要求,我们提取的TObject不能仍然保持在TFile关闭时delete的列表里。于是TObject包含了一个改变目录的方式,

TH2D * GetTH2DFromFile(const char * fn, const char * classname)
{
    TFile * f = new TFile(fn, "read");
    TH2D * h2d = (TH2D *) f->Get(classname)->Clone();
    h2d->SetDirectory(0);// 这个就是
    return h2d;
}

这样就完成了how to remain a TObject after the corresponding TFile is closed。
ref
https://root.cern.ch/phpBB3/viewtopic.php?t=3170

Operation not allowed after ResultSet closed

09-28

我有一个问题就是,我的RS与Stmt没有交错使用为什么会出现这个错误呢?小弟先在些谢过了rn错误:Operation not allowed after ResultSet closedrnrn在StrutsAction中调用Page p=new Page();p.SelectRS("select id,username from user", "where id<3", page_num, page);rnrn我的原码:rn//com.DateBase.ConnLink文件rnrnpackage com.DateBase;rnrnimport java.sql.*;rnrnpublic class ConnLink rn private Connection conn=null;rn private Statement stmt=null;rn// private ResultSet rs=null;rn rn public Statement DBlink() throws SQLExceptionrn rn try rn Class.forName("com.mysql.jdbc.Driver");rn conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/jiuzhou","root","123456");rn stmt=conn.createStatement();rn catch (ClassNotFoundException e) rn // TODO Auto-generated catch blockrn e.printStackTrace();rn finallyrn DBclean(null);rn rn return stmt;rn rn rn public void DBclean(ResultSet rs)rn rn try rn if(rs!=null)rn rn rs.close();rn rn if(stmt!=null)rn rn stmt.close();rn rn if(conn!=null)rn rn conn.close();rn rn catch (SQLException e) rn // TODO Auto-generated catch blockrn e.printStackTrace();rn rn rnrnrnrn//com.SpreadPage.Page文件rnpackage com.SpreadPage;rnrnimport java.sql.ResultSet;rnimport java.sql.SQLException;rnimport java.sql.Statement;rnimport com.DateBase.*;rnrnpublic class Page extends ConnLinkrn private Statement stmt=null;rn private ResultSet rs=null;rn private String select=null;rn private String where=null;rn private String SQL=null;rnrn private int num=0;rn private int page=0;rn //搜索去向 搜索条件 当前第几页 每页条数rn public ResultSet SelectRS(String select,String where,int page_num,int page)rn rn// this.select=select;rn// this.where=where;rn this.num=page_num;rn this.page=page;rn String sql=select+"limit "+(page_num*page)+","+(page_num*page+page)+" "+where;rn SQL=select+" "+where;rn try rn stmt=DBlink();rn System.out.println(sql);rn rs=stmt.executeQuery(sql);rn catch (SQLException e) rn // TODO Auto-generated catch blockrn e.printStackTrace();rn finallyrn DBclean(rs);rn rn return rs;rn rn //获得总记录数rn public int getRow()rn rn int row=0;rn // String SQL="select count(*) from jj "+where;rn try rn if(rs!=null)rn rn rs.close();rn rn if(stmt==null)rn rn System.out.println("Stmt无连接");rn return 0;rn rn System.out.println(SQL);rn rs=stmt.executeQuery(SQL);rn rs.first();rn rs.last();rn row=rs.getRow();rn catch (SQLException e) rn // TODO Auto-generated catch blockrn e.printStackTrace();rn rn return row;rn rn rn public int getFrist()rn rn return 0;rn rn public int getBack()rn rn return (getRow()/page)+1;rn rn public int getLast()rn rn if(num<=0)rn rn return 0;rn rn return (num-1);rn rn public int getNext()rn rn int back=getBack();rn if(num>=back)rn rn return num;rn rn return (num+1);rn rnrnrn

No operations allowed after statement closed

03-28

[code=java]21:01:11,919 WARN org.hibernate.jdbc.AbstractBatcher:302 - exception clearing maxRows/queryTimeoutrncom.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after statement closed.rn at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)rn at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)rn at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)rn at java.lang.reflect.Constructor.newInstance(Constructor.java:513)rn at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)rn at com.mysql.jdbc.Util.getInstance(Util.java:386)rn at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1015)rn at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:989)rn at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:975)rn at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:920)rn at com.mysql.jdbc.StatementImpl.checkClosed(StatementImpl.java:461)rn at com.mysql.jdbc.StatementImpl.getMaxRows(StatementImpl.java:2216)rn at org.apache.commons.dbcp.DelegatingStatement.getMaxRows(DelegatingStatement.java:237)rn at org.hibernate.jdbc.AbstractBatcher.closeQueryStatement(AbstractBatcher.java:298)rn at org.hibernate.jdbc.AbstractBatcher.closeQueryStatement(AbstractBatcher.java:234)rn at org.hibernate.loader.Loader.getResultSet(Loader.java:1967)rn at org.hibernate.loader.Loader.doQuery(Loader.java:802)rn at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274)rn at org.hibernate.loader.Loader.doList(Loader.java:2542)rn at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2276)rn at org.hibernate.loader.Loader.list(Loader.java:2271)rn at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:459)rn at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:365)rn at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196)rn at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1268)rn at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)rn at com.jmy.logic.JEssayLogic.find(JEssayLogic.java:167)rn at com.jmy.service.impl.JEManagerImpl.find(JEManagerImpl.java:47)rn at com.jmy.action.JmyOnePage.loadPage(JmyOnePage.java:47)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)rn at java.lang.reflect.Method.invoke(Method.java:597)rn at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:453)rn at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:292)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:255)rn at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:256)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)rn at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176)rn at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)rn at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:265)rn at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)rn at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)rn at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:138)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)rn at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:211)rn at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)rn at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:211)rn at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)rn at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:190)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)rn at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)rn at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:90)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)rn at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:243)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)rn at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)rn at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)rn at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:145)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)rn at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:171)rn at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)rn at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:176)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)rn at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)rn at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:192)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)rn at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:187)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)rn at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)rn at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:510)rn at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)rn at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)rn at org.apache.catalina.core.StandardWrapperValve.invrnrn配置文件是[code=html]rn rn rn rn com.wds.registration.modelrn com.jmy.essay.modelrn com.jmy.picture.modelrn rn rn rn rn rn org.hibernate.dialect.MySQLDialectrn rn truern updatern truern truern truern truern rn rn rn rn [/code]rnjava调用代码[code=java]public List find(List e_EMLs) rn /** select title,author from List(table'name) order by id desc LIMIT 8 **/rn List tbes = new ArrayList();rn tbes.clear();rn tbes.add("E_Rcm");rn tbes.add("E_Egh");rn tbes.add("E_Mword");rn tbes.add("E_Bword");rn tbes.add("E_Fas");rn tbes.add("E_Clas");rnrn e_EMLs = new ArrayList();rn String sql1 = "select id,title,author,rlTime,tbName from ";rn String sql2 = " order by id desc";rn int stNO = 0, elNO = 8;rn Session session = sessionFactory.openSession();rn for (int i = 0; i < tbes.size(); i++) rn List<_essay_Model> e_Ml = new ArrayList<_essay_Model>();rn E_EML e_EML = new E_EML();rnrn Query query = session.createQuery(sql1 + tbes.get(i) + sql2);rn query.setFirstResult(stNO);rn query.setMaxResults(elNO);rn List l = query.list();rnrn for (int j = 0; j < l.size(); j++) rn Object[] objs = (Object[]) l.get(j);rn _essay_Model em = new _essay_Model();rn em.setId((Integer) objs[0]);rn em.setTitle((String) objs[1]);rn em.setAuthor((String) objs[2]);rn DateFormat dformat = new SimpleDateFormat("yyyy-MM-dd");rn em.setRltoStr(dformat.format((Timestamp) objs[3]));rn em.setTbName((String) objs[4]);rn e_Ml.add(em);rn rn e_EML.setE_Ms(e_Ml);rn e_EMLs.add(e_EML);rn rn rn session.close();rn sessionFactory.close();rn return e_EMLs;rn rn[/code]

没有更多推荐了,返回首页

私密
私密原因:
请选择设置私密原因
  • 广告
  • 抄袭
  • 版权
  • 政治
  • 色情
  • 无意义
  • 其他
其他原因:
120
出错啦
系统繁忙,请稍后再试