You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by ha...@apache.org on 2002/07/05 16:40:41 UTC
cvs commit: xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp EsqlHelper.java
haul 2002/07/05 07:40:41
Modified: src/java/org/apache/cocoon/components/language/markup/xsp
EsqlHelper.java
Log:
Support xLOBs with CallableStatements
Revision Changes Path
1.11 +75 -1 xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/EsqlHelper.java
Index: EsqlHelper.java
===================================================================
RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/EsqlHelper.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- EsqlHelper.java 10 Jun 2002 09:01:52 -0000 1.10
+++ EsqlHelper.java 5 Jul 2002 14:40:41 -0000 1.11
@@ -53,6 +53,7 @@
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.Reader;
+import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.io.InputStream;
import java.sql.Blob;
@@ -112,6 +113,30 @@
}
}
+ /** returns byte array from BLOB
+ */
+ public final static byte[] getBlob(CallableStatement cs, int column) throws java.lang.Exception {
+
+ InputStream reader = null;
+ byte[] buffer = null;
+
+ try {
+ Blob dbBlob = cs.getBlob(column);
+ int length = (int) dbBlob.length();
+ reader = dbBlob.getBinaryStream();
+ buffer = new byte[length];
+ reader.read(buffer);
+ reader.close();
+ if (reader != null)
+ reader.close();
+ if (buffer == null)
+ return null;
+ return buffer;
+ } catch ( Exception e) {
+ throw new RuntimeException("Error getting blob data: " + e.getMessage());
+ }
+ }
+
/** returns Unicode encoded string from CLOB or String column
*/
public final static String getStringOrClob(ResultSet set, String column) throws RuntimeException {
@@ -154,6 +179,30 @@
}
}
+ /** returns Unicode encoded string from CLOB or String column
+ */
+ public final static String getStringOrClob(CallableStatement cs, int column) throws java.lang.Exception {
+
+ Reader reader = null;
+ char[] buffer = null;
+
+ try {
+ Clob dbClob = cs.getClob(column);
+ int length = (int) dbClob.length();
+ reader = new BufferedReader(dbClob.getCharacterStream());
+ buffer = new char[length];
+ reader.read(buffer);
+ reader.close();
+ if (reader != null)
+ reader.close();
+ if (buffer == null)
+ return "";
+ return new String(buffer);
+ } catch ( Exception e) {
+ throw new RuntimeException("Error getting clob data: " + e.getMessage());
+ }
+ }
+
/** returns ascii string from CLOB or String column
*/
@@ -196,6 +245,31 @@
}
}
+ return result;
+ }
+
+ /** returns ascii string from CLOB or String column
+ */
+ public final static String getAscii(CallableStatement cs, int column) {
+ InputStream asciiStream = null;
+ String result = null;
+
+ try {
+ byte[] buffer = null;
+ Clob dbClob = cs.getClob(column);
+ int length = (int) dbClob.length();
+ asciiStream = new BufferedInputStream(dbClob.getAsciiStream());
+ buffer = new byte[length];
+ asciiStream.read(buffer);
+ asciiStream.close();
+ result = (buffer!=null? new String(buffer) : null);
+ } catch (Exception e) {
+ throw new RuntimeException("Error getting clob data: " + e.getMessage());
+ } finally {
+ if (asciiStream != null) try {asciiStream.close();} catch (Exception ase) {
+ throw new RuntimeException("Error closing clob stream: " + ase.getMessage());
+ }
+ }
return result;
}
----------------------------------------------------------------------
In case of troubles, e-mail: webmaster@xml.apache.org
To unsubscribe, e-mail: cocoon-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-cvs-help@xml.apache.org