How to read BLOBs as "Java.io.Reader"

Hello,
I have a problem dealing with BLOBs in JDBC. I want to get a BLOB as a "java.io.Reader". I have written the following code:
class Db_templates {
public static Reader select(int tpl_id) {
try {
Connection connection = ... ;
Reader retour = null;
String strSQL = "SELECT tpl_blob FROM templates WHERE tpl_id = ?";
PreparedStatement ps = connection.prepareStatement(strSQL);
ps.setInt(1, tpl_id);
ResultSet rset = ps.executeQuery();
if (rset.next()) {
oracle.sql.BLOB blob = (BLOB)rset.getObject(1);
retour = blob.characterStreamValue();
rset.close();
ps.close();
connection.close();
return retour;
} catch (SQLException e) {
return null;
Then I try to call this method in a JSP file (Tomcat 4.0 as JSP container) with the following lines:
Reader i = Db_templates.select(42);
out.println(i.ready());
char buf[] = new char[1000];
try {
int retour = i.read(buf, 1, 900);
} catch (IOException e) {
out.println(e.toString());
The method i.ready() returns false with no IOException thrown.
The method i.read() fails to execute with the following errors:
java.lang.NullPointerException
at oracle.sql.LobPlsqlUtil.plsql_read(LobPlsqlUtil.java:911)
at oracle.sql.LobPlsqlUtil.plsql_read(LobPlsqlUtil.java:52)
at oracle.jdbc.dbaccess.DBAccess.lobRead(DBAccess.java:658)
at oracle.sql.LobDBAccessImpl.getBytes(LobDBAccessImpl.java:95)
at oracle.sql.BLOB.getBytes(BLOB.java:175)
at oracle.jdbc.driver.OracleBlobInputStream.needBytes(OracleBlobInputStream.java:126)
at oracle.jdbc.driver.OracleBufferedStream.read(OracleBufferedStream.java:108)
at oracle.jdbc.driver.OracleConversionReader.needChars(OracleConversionReader.java:151)
at oracle.jdbc.driver.OracleConversionReader.read(OracleConversionReader.java:119)
at org.apache.jsp.essai2$jsp._jspService(essai2$jsp.java:87)
Any ideas?
Thanks,
Nicolas

Normally, Firefox has two different behaviors for the down arrow key, assuming it is not inside a form control:
* Scroll the page
* With caret browsing turned on, move the cursor down one line
If you are accustomed to the down arrow key moving among search results so you can press the Enter key to load them, and you are using Google, this is due to a script in the results page intercepting those keys and changing what they normally do.
I have only tested Windows myself, so I don't know whether this is generally available when using Google in your distribution of Linux. If it is, then the question would be: why not on your Firefox? Hmm...

Similar Messages

  • How to extract  Blob using java

    hai
    have a peace day.
    i want to extract the data from BLOB thro java
    i using getblob, but i don,t know properly
    please tell any ideas r give some sample codes
    thank u
    raja

    i want to extract the data from BLOB thro javaYou can use getBytes or getBinaryStream to extract the expected data stream to do more.

  • Java.io.Reader to String conversion

    I am working on a SOAP project with Jaxm and I retreive the result as a Reader, but I need to convert it into a String.
    I did the following code but it is incredibely slow with a big reply (280kb) as I retrieve each character one after each other.
    Does a faster solution exist ?
    // Soap call
    SOAPMessage reply = m_conn.call(message, endpoint);
    java.util.Iterator it = reply.getAttachments();
    // First attachment returned by the server hold my result
    AttachmentPart resultAttachment = (AttachmentPart) it.next();
    StreamSource resultStreamSource = (StreamSource) resultAttachment.getContent();
    // Converts java.io.Reader to String
    java.io.Reader resultReader = resultStreamSource.getReader();
    String result = "";
    int charValue = 0;
    while ((charValue = resultReader.read()) != -1) {
       result = result + (char) charValue;

    use a BufferedReader and create a large char[] (64k or something)
    then use
    char[] cbuf = new char[65536];
    StringBuffer stringbuf = new StringBuffer();
    int read_this_time = 0;
    while (read_this_time != -1) {
    read_this_time = BufferedReader.read(cbuf,0,65536);
    stringbuf.append(cbuf,0,read_this_time);
    }//end while
    StringBuffer is faster than String concatenation because when java concatenates strings it creates a new object every time. StringBuffer just stores and appends the string without creating new objects.

  • How i can make valid java appliacation and how

    i am novice in java and i want to make good and valid application that i can run from server any body can tell me how i can make this or any link for any project online or build on net with deployment details
    A.R

    JAXP api can be used to read xml from java
    Cheers :)

  • How to read card reader (bar code reader) in simple java program ?

    hai all
    how to manipulate (read/write) card readers (or bar code reader ) in
    a java program ?
    should i import any particular package library ?
    pls give me any sample code or tutorials or tools, etc (whatever you have) .
    i am new to this card reader category
    its very urgent
    thank you .

    Nearly all card readers and barcode readers I've ever seen simply stick their input right onto stdin, so you can capture it just as if it had been typed in on a keyboard

  • How to open/read file using Java in Unix?

    Hi Friends,
    Can you please help me out how to open/read file using java in unix os? I have create one text file in "/home/test.txt" in unix environment. How to open the same file & read using java code?
    - Hiren Modi

    http://java.sun.com/docs/books/tutorial/essential/io/index.html

  • How to read OVD using java

    Hi all,
    how to access OVD using Java?
    Thanks,
    Kumar.P

    Hi,
    You can just normal LDAP API codes to connect to OVD the same way you connect to other LDAP servers.
    PFB sample code for connecting to OVD.
    Properties props = new Properties();
    try {
    props.load(new FileInputStream("LdapCredentials.Properties"));
    } catch (IOException e) {
    // TODO
    ldapurl = "ldap://hostname:390";
    ldapUser = "cn=orcladmin,ou=Org12,dc=ovid,dc=com";
    userPassword = "welcome1"; //"Killtheking123456";
    userContext = "ou=Join1,dc=ovid,dc=com";
    Now, you have to get Directory Context as shown below.
    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY,
    "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, ldapurl);
    env.put(Context.SECURITY_AUTHENTICATION, "simple");
    env.put(Context.SECURITY_PRINCIPAL, username);
    env.put(Context.SECURITY_CREDENTIALS, password);
    //Initialize the Directory context
    DirContext dCtx = new InitialDirContext(env);
    Then you can perform search operations or new user creation etc., as you wish.
    Does this help?
    -Mahendra.

  • How can we make the ms-word data as read-only using java code?

    How can we make the ms-word data as read-only using java code?

    MVSK wrote:
    By using java code i opened a file in ms-word. But the data i want to display as read-only. that means should not change it.I don't think you can do that. Display pdf documents instead.

  • How to NOT ignore java beans read only properties when serializing Java to AS?

    As stated in the Adobe LCDS documentation, the read-only properties of a java bean are ignored in the AMF serialization process.
    Would you know what to do so that Java beans read only properties do not get discarded when sending it via BlazeDS AMF?
    Many thanks in advance.

    Hi,
    I've managed to get what I needed by using a shift register + event structure as suggested by Adnan. However, I face another problem after implementing SR+event. I've attached two files, first the original program and second the updated program using SR + event. (it's only the jpg file as I've forgotten to save the labview program, will upload the program by tomorrow.
    In the original program, I have an elapsed time that is able to run continuously when I run the program. In the updated program, my elapsed time don't seem to run continuously when I run the program (as shown by elapsed time indicator). I need the elapsed time to run continuously as a input to calculate my motor profile.
    I suppose this is caused by the introduction of the event structure, will adding a case structure to wrap the event structure solve the problem or is there another way to get pass this. Appreciate if someone could drop me a pointer or two.
    Thanks
    Attachments:
    Mar 16 - continuous elapsed time.png ‏12 KB
    Mar 16 - elapsed time not continuous after introducing shift register + event structure.png ‏17 KB

  • Can I include a text file to read from within java?

    I have a config file I need to read within a java program called config.xml.
    I want to reference this document, but don't now how to without using '..new(File("config.xml"))' and this forces me to put it in a directory somewhere.
    I just want to reference it from a jar file. For example, if I put it in a jar called config.jar, and added that to my CP - how do I reference it?
    THanks

    Great - thanks.
    One more question - Is configs in this case a java package that I would inlclude with my other packages?
    For example, my main package is: main - it contains several packages with all my code. - I created a new folder in my Jbuilder environment in the same directory as the main package - called in configs - then put the config.xml file in there. If I add the package configs - it doesn't show the conifg.xml within the tree viewer of Jbuilder...do I need to put a package identification at the top of the XML file like in Java - somehting like package main.configs?
    THanks, again

  • How to handle blob data with java and mysql and hibernate

    Dear all,
    I am using java 1.6 and mysql 5.5 and hibernate 3.0 . Some time i use blob data type . Earlier my project's data base was oracle 10g but now i am converting it to Mysql and now i am facing problem to save and fetch blob data to mysql database . Can anybody give me the source code for blob handling with java+Mysql+Hibernate
    now my code is :--
    ==================================================
    *.hbm.xml :--
    <property name="image" column="IMAGE" type="com.shrisure.server.usertype.BinaryBlobType" insert="true" update="true" lazy="false"/>
    ===================================================
    *.java :--
    package com.shrisure.server.usertype;
    import java.io.OutputStream;
    import java.io.Serializable;
    import java.sql.Blob;
    import java.sql.Connection;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Types;
    import javax.naming.InitialContext;
    import javax.sql.DataSource;
    import oracle.sql.BLOB;
    import org.hibernate.HibernateException;
    import org.hibernate.usertype.UserType;
    import org.jboss.resource.adapter.jdbc.WrappedConnection;
    import com.google.gwt.user.client.rpc.IsSerializable;
    public class BinaryBlobType implements UserType, java.io.Serializable, IsSerializable {
    private static final long serialVersionUID = 1111222233331231L;
    public int[] sqlTypes() {
    return new int[] { Types.BLOB };
    public Class returnedClass() {
    return byte[].class;
    public boolean equals(Object x, Object y) {
    return (x == y) || (x != null && y != null && java.util.Arrays.equals((byte[]) x, (byte[]) y));
    public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException {
    BLOB tempBlob = null;
    WrappedConnection wc = null;
    try {
    if (value != null) {
    Connection oracleConnection = st.getConnection();
    if (oracleConnection instanceof oracle.jdbc.driver.OracleConnection) {
    tempBlob = BLOB.createTemporary(oracleConnection, true, BLOB.DURATION_SESSION);
    if (oracleConnection instanceof org.jboss.resource.adapter.jdbc.WrappedConnection) {
    InitialContext ctx = new InitialContext();
    DataSource dataSource = (DataSource) ctx.lookup("java:/DefaultDS");
    Connection dsConn = dataSource.getConnection();
    wc = (WrappedConnection) dsConn;
    // with getUnderlying connection method , cast it to Oracle
    // Connection
    oracleConnection = wc.getUnderlyingConnection();
    tempBlob = BLOB.createTemporary(oracleConnection, true, BLOB.DURATION_SESSION);
    tempBlob.open(BLOB.MODE_READWRITE);
    OutputStream tempBlobWriter = tempBlob.getBinaryOutputStream();// setBinaryStream(1);
    tempBlobWriter.write((byte[]) value);
    tempBlobWriter.flush();
    tempBlobWriter.close();
    tempBlob.close();
    st.setBlob(index, tempBlob);
    } else {
    st.setBlob(index, BLOB.empty_lob());
    } catch (Exception exp) {
    if (tempBlob != null) {
    tempBlob.freeTemporary();
    exp.printStackTrace();
    st.setBlob(index, BLOB.empty_lob());
    // throw new RuntimeException();
    } finally {
    if (wc != null) {
    wc.close();
    public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws HibernateException, SQLException {
    final Blob blob = rs.getBlob(names[0]);
    return blob != null ? blob.getBytes(1, (int) blob.length()) : null;
    public Object deepCopy(Object value) {
    if (value == null)
    return null;
    byte[] bytes = (byte[]) value;
    byte[] result = new byte[bytes.length];
    System.arraycopy(bytes, 0, result, 0, bytes.length);
    return result;
    public boolean isMutable() {
    return true;
    public Object assemble(Serializable arg0, Object arg1) throws HibernateException {
    return assemble(arg0, arg1);
    public Serializable disassemble(Object arg0) throws HibernateException {
    return disassemble(arg0);
    public int hashCode(Object arg0) throws HibernateException {
    return hashCode();
    public Object replace(Object arg0, Object arg1, Object arg2) throws HibernateException {
    return replace(arg0, arg1, arg2);
    =================================================================
    can anyone give me the source code for this BinaryBlobType.java according to mysql blob handling ..

    Moderator action: crosspost deleted.

  • Java.io.Reader - java.io.InputStream

    Hi!
    Is there a way to wrap a java.io.Reader into an java.io.InputStream (like java.io.InputStreamReader does but in the other direction)?
    I found now class doing this job (deduced from java.io.InputStream, taking an java.io.Reader as Constructor Parameter) :-/
    If I want to write my own wrapper I've got two problems:
    * If I want to read data I have to split the char which I read from the wrapped java.io.Reader into a high and a low byte and than return two values.
    * But if I want to read text I can't just split the char into two bytes but I have to convert it
    How can I solve this problem?

    Is there a way to wrap a java.io.Reader into an java.io.InputStream (like java.io.InputStreamReader does but in the other direction)?Why don't you explain what the real problem is? I suspect that there's a solution, but you need to state it. What was the creator and source of the information (file?) that you're trying to read that contains "data" and, apparently, Java characters in a different charset?

  • Reading BLOB from SQL Server 2005 using DB Link from Oracle 10g

    Hi All,
    I am trying to read a table's data from SQL Server 2005 using ODBC DB Link created in Oracle 10g (10.2.0.3/4) database. I am not using oracle gateway.
    I am able read all data except for the BLOB data from SQL server 2005. It gives error given below when I try to execute query SELECT * from T_TRANSACTION_DATA@sdeslink inside a stored procedure:
    ORA-22992: cannot use LOB locators selected from remote tables
    Kindly help how to read BLOB from SQL server 2005 inside Oracle 10g.
    Best Regards!
    Irfan

    Irfan,
    If you can read the blob data using 10.2 HSODBC then there should be no problem using the 11g gateway.
    I recommend you download the latest version which is 11.2.0.3 available from My oracle Support as -
    Patch 10404530: 11.2.0.3.0 PATCH SET FOR ORACLE DATABASE SERVER
    This is a full version and does not need a previous version to have bene installed. When installing it needs to be in a completlely separate ORACLE_HOME from the existing 11.2 install.
    For the Ora-22992 problem have a look at this note in My Oracle Support -
    Ora-22992 has a workaround in 10gR2 (Doc ID 436707.1)
    Regards,
    Mike

  • Compiling message "cannot read" (new to java)

    Sorry about yet another question on compiling. I'm new to java. I've read alot of the threads on this, but my HelloJava.java won't compile.
    I'm working on w2k. I've set my path to
    %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;c:\j2sdk1.4.0\bin
    using the environment variables in the system properties box.
    This seems to work fine.
    but I keep getting the "cannot read" when compiling.
    I've created a classpath variable in the environment variables
    CLASSPATH = .;C:\src
    and my java file is definately .java not .java.txt and it's in the src folder on my c drive.
    Do I need to set classpath? Also I've put my HelloJava.java file in the same folder as my javac and it still won't compile. What am I doing wrong?
    By the way, the HelloJava file came from the book "Learning Java".
    thanks in advance.

    OK -
    If you place your .java files in C:\src, to compile you must either
    1. Go to (change the current directory to, using cd command) c:\src and then enter "javac ...."
    or
    2 From any directory enter "javac C:\src\...."
    Classpath is used by javac and java, but not in this way.
    Read here for the full story:
    The Path is a set of pointers that Windows uses to locate programs that you execute, like javac.exe and java.exe. This setting is explained here:
    http://java.sun.com/j2se/1.4/install-windows.html
    Scroll down to: 5. Update the PATH variable
    The CLASSPATH is another set of pointers that is used by Java to find the files that you create and want compiled and/or run. This setting is explained here:
    Setting the Classpath:
    http://java.sun.com/j2se/1.4/docs/tooldocs/windows/classpath.html
    [NOTE: always start your classpath with ".;" which means the current directory. See my classpath, below]
    How Classes are Found:
    http://java.sun.com/j2se/1.4/docs/tooldocs/findingclasses.html

  • How to skip the '\n' char when reading with BufferedReader

    Hello to all the comunity that is at these forums, ;)
    I'm a venezuelan IT student, and as many arround here, I'm looking for some help with this homework...
    well the thing is that I need to read from the System.in untill I get the "" String. Well the initial idea was to make a BufferedReader object and put the br.readLine(); method inside a recursive method, like this:
       import java.io.*;
        public class P1_diccionary {
          String[] diccionario;
          int cont=0;
           void llenarDiccionario(String linea, String[] auxi)throws IOException{
             if(linea.compareTo("")!=0){
                 int aux = cont++;
                 diccionario = new String[cont];
                 for(int i=0;i<auxi.length;i++)
                     diccionario=auxi[i];
    diccionario[aux]=linea;
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    llenarDiccionario(reader.readLine(),diccionario);
    well, I think this one it's a nice idea, however, it doesn't work for me because the input is going to be just like this:
    word1: concept1...
    word2: concept2...
    word3: concept3...
    word4: concept4...
    and! it's going to be pasted on the console (that is "ctrl+c" then "ctrl+v")... that's the real problem that I have, the method that I did reads some lines not all of them, I think it's because there is no synchronization (guessing) between the ctrl+v and the execution of the program...
    so I thought about skiping the '\n' char, to do this I checked the readLine() method of the BufferedReader and found out that it calls a
    readLine(boolean ignoreLF)method and that ignoreLF and skipLF -boolean form the class- determine whether readLine() will skip the '\n' char or not:
    boolean omitLF = ignoreLF || skipLF;ok now the question: how do I make ignoreLF or skipLF = true? I tried to look more in the BufferedReader class but I didn't see how to change the skipLF value...
    well guess that's all, I'll really apriciate all of your help, and any other ideas that you might have to solve the problem...
    well thanks to everybody and see ya ;)

    Use read() instead of readLine(). This method will read characters, and does not treat the EOL charactger the same way. Just keep reading until you find a sequence of characters (two EOL sequences in a row) that matches your end condition. Just be careful, since different OSs have different EOL sequences ... \n, \n\r, or \r. Also, remember that you will have to deal with the EOL sequences. They will not be discarded automatically.
    You can also use read( char[], int, int) to read as many characters as you want, without regard to EOL sequences. This will only stop reading when EOF is reached, or when the next read will cause the underlying stream to block, or when you have read a specified number of characters. Again, this will not terminate at a EOL sequence, and will include the EOL sequences in your array.
    As far as readLine() is concerned, I think you want to stop when you have TWO successive reads that equal "".
    � {�                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

Maybe you are looking for

  • Keep getting error message from 'Cron Daemon'

    I have been running an Xserve G4 with Mac OS X Server 10.3.9 as a mail server and web server for several years now with no problems. Recently, however, I tried to set up a mailing list, which I had never done before. When I tried doing this, OS X aut

  • IPhoto v.8.1.2 can't use the Facebook photo upload button - get error

    Everytime I hit the Facebook button down at the bottom of iPhoto and try to log in, I get an error that states, "An error occurred with iPhoto Uploader. Please try again later." Have no clue what the problem might be. Did make sure iPhoto was set up

  • How can i change the aspect ratio in Event Library?

    the videos i imported to iMovie from iMac look horizontally distorted. i took them with an iPhone4. when importing them, i chose 16:9 ratio, this may be the reason. i can not change the ratio to 3:2. Thanks.

  • BI report to get count

    Hello BI Gurus, I have a BI report where we require to have values in the following format.. For Plant: X OVERALL                               Sep-07          Oct-07     Nov-07     Dec-07     Jan-08     Feb-08 Total No of Machines         1         

  • Using BT FON with a different home router

    I currently have a BT Home Hub and have opted in to BT FON, which I have been using quite a bit when away from home. However, I am thinking about switching to a different router at home, for unrelated reasons. Am I correct in my interpretation that I