无法将 clob 转换为字符串

发布于 2024-08-21 19:26:53 字数 3283 浏览 7 评论 0原文

我正在尝试将我的 clob 对象转换为字符串以在我的 JSTL 页面上显示它,因为我正在编写以下代码,

public String convertClobToString(Clob clob){
     String toRet="";
     if(clob!=null)
     {
         try
         {
             long length=clob.length();
             toRet=clob.getSubString(1, (int)length);
         }
         catch(Exception ex)
         {
             TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
             ex.printStackTrace();
         }
     }
     return toRet;
 }

但是在使用“long length = clob.length()”计算长度时,它抛出以下异常

java.sql.SQLException: Must be logged on to server

at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
at oracle.jdbc.dbaccess.DBError.check_error(DBError.java:1160)
at oracle.jdbc.ttc7.TTC7Protocol.assertLoggedIn(TTC7Protocol.java:2196)
at oracle.jdbc.ttc7.TTC7Protocol.lobLength(TTC7Protocol.java:2698)
at oracle.sql.LobDBAccessImpl.length(LobDBAccessImpl.java:468)
at oracle.sql.CLOB.length(CLOB.java:214)
at org.hibernate.lob.SerializableClob.length(SerializableClob.java:33)
at com.starcj.cmt.application.dao.ApplicationDaoImpl.convertClobToString(ApplicationDaoImpl.java:110)
at com.starcj.cmt.termsandcondmgmt.dao.TermsAndCondDaoImpl.getAllActiveTermsandcond(TermsAndCondDaoImpl.java:91)
at com.starcj.cmt.termsandcondmgmt.service.TermsAndCondServiceImpl.getAllActiveTermsAndCond(TermsAndCondServiceImpl.java:43)
at com.starcj.cmt.termsandcondmgmt.controller.TermsAndCondListingCMTController.handleRequest(TermsAndCondListingCMTController.java:66)
at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:875)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:807)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:501)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Unknown Source)

exceptoin isMust 必须登录到服务器

,但我从数据库获取 clob 对象

I am trying to convert my clob object to string to display that on my JSTL page for that I am writting the following code

public String convertClobToString(Clob clob){
     String toRet="";
     if(clob!=null)
     {
         try
         {
             long length=clob.length();
             toRet=clob.getSubString(1, (int)length);
         }
         catch(Exception ex)
         {
             TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
             ex.printStackTrace();
         }
     }
     return toRet;
 }

but while counting the length using "long length = clob.length()" its throwing following exception

java.sql.SQLException: Must be logged on to server

at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
at oracle.jdbc.dbaccess.DBError.check_error(DBError.java:1160)
at oracle.jdbc.ttc7.TTC7Protocol.assertLoggedIn(TTC7Protocol.java:2196)
at oracle.jdbc.ttc7.TTC7Protocol.lobLength(TTC7Protocol.java:2698)
at oracle.sql.LobDBAccessImpl.length(LobDBAccessImpl.java:468)
at oracle.sql.CLOB.length(CLOB.java:214)
at org.hibernate.lob.SerializableClob.length(SerializableClob.java:33)
at com.starcj.cmt.application.dao.ApplicationDaoImpl.convertClobToString(ApplicationDaoImpl.java:110)
at com.starcj.cmt.termsandcondmgmt.dao.TermsAndCondDaoImpl.getAllActiveTermsandcond(TermsAndCondDaoImpl.java:91)
at com.starcj.cmt.termsandcondmgmt.service.TermsAndCondServiceImpl.getAllActiveTermsAndCond(TermsAndCondServiceImpl.java:43)
at com.starcj.cmt.termsandcondmgmt.controller.TermsAndCondListingCMTController.handleRequest(TermsAndCondListingCMTController.java:66)
at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:875)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:807)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:501)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Unknown Source)

Exceptoin isMust be logged on to server

but I am getting the clob object from database

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

污味仙女 2024-08-28 19:26:53

在您的休眠实体(我们看不到)中,将属性声明为 String 类型,并用 @Lob 对其进行注释(同样,我不知道您是否使用注释或 XML),并且无需任何手动转换即可工作。

发生这种情况是因为在您尝试解析实体时,会话和底层连接已关闭,因此您无法从数据库流式传输 CLOB 的值。

上述解决方案的替代方案可能是使用 OpenSessionInView 过滤器。它将让您在渲染视图(即您的 jsps)时打开会话(和底层数据库连接)

In your hibernate entity (which we can't see) declare the property to be of type String and annotate it with @Lob (again, I don't know whether you are using annotations or XML), and it will work without the need for any manual conversion.

This happens because at the time you are trying to parse the entity, the session and the underlying connection are closed, so you can't stream the value of the CLOB from the database.

An alternative for the above solution might be to use an OpenSessionInView Filter. It will let you have the session (and the underlying database connection) open while rendering the view (i.e. your jsps)

音栖息无 2024-08-28 19:26:53

你从哪里得到 CLOB?创建它的连接是否仍然打开?
错误消息似乎表明数据库连接已在此期间关闭。
如果您使用 Hibernate,Hibernate Session 是否仍然打开?

Where are you getting the CLOB from? Is the Connection that created it still open?
The error message seems to indicate the database connection has been closed in the meantime.
If you are using Hibernate, is the Hibernate Session still open?

冬天旳寂寞 2024-08-28 19:26:53

Clobresume = Hibernate.createClob("这是Clob");

Clob resume = Hibernate.createClob ( "This is Clob");

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文