robixit Posted May 13, 2009 Share Posted May 13, 2009 Hi, i apologize for my englishI am trying to show an oracle clob column in a 3.5.1 ireport field.Retrieving field from ireport query, define this element as "oracle.sql.CLOB" but i don't know how to cast the item in the class expression of the field.In version 3.0 i had a class expression as "java.lang.string" to cast the clob column, and i didn't have problems.Thanks in advance.Robi-------------ciao Giulio, scusa se scrivo in italiano ma il mio inglese è pessimo (come hai potuto notare).Inizio con il farti i miei complimenti per questo magnifico strumento.Premetto che NON sono uno sviluppatore java, uso ireport attraverso delle jsp sviluppate da me, per creare reports da pagine web create con il tool APEX della oracle (application express). Brevemente.. ho l'esigenza di stampare delle grosse porzioni di testo (clob) formattati con un markup di tipo html. Ho fatto qualche prova e, nella versione 3.0 classica mi sembra di aver capito che alcuni tipi di tag potevo usarli e altri no (alcuni ho visto che addirittura mandavano in dump il report, tipo le liste). Ho pensato quindi di passare all'ultima versione su ide netbean, e ora non capisco come definire queste colonne clob, perchè la query me le vede come oracle.sql.CLOB ma poi la classe espressione del field (java.lang.string) non riesce ad eseguire il cast. Ho provato ad anteporre nell'espressione del campo i doppi apici ( ""+$F{CLOB_COL} ) così il report gira ma nel campo vedo un'espressione del tipo "oracle.sql.CLOB@1d916ae".. Ti sono estremamente grato per qualsiasi aiuto potrai darmi.Robi Link to comment Share on other sites More sharing options...
Giulio Toffoli Posted May 13, 2009 Share Posted May 13, 2009 Ciao Robi,$F{CLOB_COL} is not a java.lang.String and it can not be cast to a String to get the content, in other words $F{CLOB_COL}+"" will not work.There are two options:Option 1. Create a Java class to extract the content of the CLOB (the content of the CLOB is extracted from the getAsciiStream() or getCharacterStream()). A class like that would be used in this way:MyUtilClass.getTextFromCLOB( java.sql.CLOB clob)Option 2. You can try something like: $F{CLOB_COL}.getSubString( 1, $F{CLOB_COL}.length() )This should return the whole text (as String) in the CLOB, but if the text is too large, probably some buffers will prevent to get the whole text, it worth to give it a try.GiulioP.S. Spero sia chiaro in inglese, altrimento lo riscrivo in italiano. Link to comment Share on other sites More sharing options...
robixit Posted May 14, 2009 Author Share Posted May 14, 2009 Hi Giulio,thank you so much for your help, i attach the source that i've in mind (i hope it's right)hope it can be of help for otherspublic class MyClobClass { public String clobToString(Clob clob) throws JRException { String strlob = ""; try { int bufSize = 8192; char[] buf = new char[bufSize]; Reader reader = new BufferedReader(clob.getCharacterStream(), bufSize); StringBuffer strbuf = new StringBuffer((int) clob.length()); for (int read = reader.read(buf); read > 0; read = reader.read(buf)) { strbuf.append(buf, 0, read); } strlob = strbuf.toString(); } catch (SQLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return strlob; }}in the field definition: new MyClobClass().clobToString($F{CLOB_COL}) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now