Home » Developer & Programmer » JDeveloper, Java & XML » Returning Large String from JAVA Database Function (8i DB )
icon9.gif  Returning Large String from JAVA Database Function [message #461814] Mon, 21 June 2010 11:54 Go to next message
lanciahf
Messages: 6
Registered: May 2010
Location: NJ
Junior Member
Hi All,

I'am using a java function that reads a long raw column and converts the longraw into text to be used in an XML document.

When I execute the function in a cursor or sql statement I get the following error.
ORA-24345: A Truncation or null fetch error occurred.

Thanks!

Below is my code

JAVA
DROP JAVA SOURCE IMAGE_JAVA_I;

CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED IMAGE_JAVA_I as import java.io.BufferedWriter;
import java.sql.*;
import java.io.*;
import java.text.*;
import java.util.*;
import oracle.jdbc.driver.*;
//BASE 64
import sun.misc.*;
import java.io.ByteArrayInputStream;
import java.sql.ResultSet;
import java.sql.PreparedStatement;
import java.sql.Connection;
import java.sql.SQLException;

//Oracle Extensions to JDBC

import oracle.jdbc.driver.OracleDriver;


public class NJ_IMAGE_JAVA_I {


public static String IMAGE_JAVA(String ob) {

String XML;
String col1;
String commentText;
int ctr1;
int length ;
BASE64Encoder encoder = new BASE64Encoder();
String encodedStr;
Connection conn2 = null;

try {
XML="";
conn2 = new OracleDriver().defaultConnection();

// create an SQL statement instance
Statement stmt2 = conn2.createStatement ();

ResultSet rss =
stmt2.executeQuery ("select IMAGE_DATA " + "from images " + "where image_id "+ob);

ResultSetMetaData rsmd = rss.getMetaData();

bookIdHold="";
ctr1 = 1;
length=0;
// process the ResultSet data
while (rss.next())
{ try { col1="";
bookId="";
image_chk = "";
commentText = "";
encodedStr = "";


image_chk = rss.getString(1);

if (image_chk.equals("true")) {encodedStr = encoder.encodeBuffer(rss.getBytes( 8 ));
XML ="<jdd:PhysicalFeatureImage><jdd:BinaryObject.Base64> "+encodedStr +"</jdd:BinaryObject.Base64><jdd:BinaryAvailableIndicator>"+image_chk+"</jdd:BinaryAvailableIndicator></jdd:PhysicalFeatureImage >";}
else {XML="<jdd:PhysicalFeatureImage><jdd:BinaryObject.Base64>"+"</jdd:BinaryObject.Base64><jdd:BinaryAvailableIndicator>"+image_chk+ "</jdd:BinaryAvailableIndicator></jdd:PhysicalFeatureImage>";
}

} catch (Exception e)
{ return " Code " + e;}

}


// Close all the resources
if (rss != null) {rss.close();}

if (stmt2 != null) {stmt2.close();}

if (conn2 != null) {conn2.close();}
//VERY VERY End!!!!
return XML;

}
catch (Exception ex2){
return "Exception " + ex2;
}
}



};
/

SQL Test
BEGIN
DECLARE
XML VARCHAR2(32767);
begin
select IMAGE_JAVA_I_FUNCTION(48419) IMAGE_TEST
into XML from dual;

END;
END;
/

[Updated on: Tue, 22 June 2010 07:26] by Moderator

Report message to a moderator

Re: Returning Large String from JAVA Database Function [message #462019 is a reply to message #461814] Tue, 22 June 2010 06:46 Go to previous messageGo to next message
lanciahf
Messages: 6
Registered: May 2010
Location: NJ
Junior Member
I think this is my problem
"PL/SQL string max lentgh it 32K."

Anyone know of a workarounds?
Re: Returning Large String from JAVA Database Function [message #462026 is a reply to message #462019] Tue, 22 June 2010 07:27 Go to previous messageGo to next message
Michel Cadot
Messages: 68624
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Use CLOB.

Regards
Michel
Re: Returning Large String from JAVA Database Function [message #462058 is a reply to message #462026] Tue, 22 June 2010 10:21 Go to previous message
lanciahf
Messages: 6
Registered: May 2010
Location: NJ
Junior Member
I have been trying without success, code blow compiles and works fine but the return variable is empty.


XML = XML+"</jdd:PersonPhysicalFeature>";

java.io.OutputStream out;
byte[] data = XML.getBytes();
out = XClob.getAsciiOutputStream();
out.write(data);
out.flush();
out.close();
Previous Topic: Associations in ADF
Next Topic: Javamail - Saving of "message/rfc822" to a BLOB column
Goto Forum:
  


Current Time: Thu Mar 28 04:11:50 CDT 2024