tags:

views:

36

answers:

1

hi all,

i have written a java code..using which i can insert images to my oracle data base blob data type and to retrieve from it. it's working perfectly on other systems ..but not working in my system when i want to insert an image having size more than 2kb.but from my system i m able to retrieve images of any size.. the same application is working well in other system but behaving abnormally..and some times showing cann't read from socket exception...when i try to insert a image size having more than 2 kb... plz help....

i am using typ4 driver

Following is my table structure::

Name Null? Type


NAME NOT NULL VARCHAR2(20) DESCRIPTION NOT NULL VARCHAR2(20) IMAGE NOT NULL BLOB

following is my java program to insert the image..again saying it works on other systems in same network ,which are connected to the same oracle server..but from system showing problem when i try to upload an image having size more than 2kb.

package com.smruti.image;

import java.io.File; import java.io.FileInputStream; import java.io.; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.;

public class InsertImage { private static String url = "jdbc:oracle:thin:@server3:1521:server3"; private static String username = "system"; private static String password = "manager";

public static void main(String[] args) throws Exception {
    Connection conn = null;
    InputStream fis = null;
    try {
        Class.forName("oracle.jdbc.driver.OracleDriver");
        conn = DriverManager.getConnection(url, username, password);
        conn.setAutoCommit(false);

        String sql = "INSERT INTO pictures VALUES (?, ?, ?)";
        PreparedStatement stmt = conn.prepareStatement(sql);
        stmt.setString(1, "scare.jpg");
        stmt.setString(2, "scare image");

        File image = new File("C:\\images.jpeg"); 
        fis = new FileInputStream(image);
        int ilen=(int) image.length();
        System.out.println(ilen);
        System.out.println(fis);
        stmt.setBinaryStream(3, fis, ilen);
        stmt.execute();


    System.out.println("this is upto b4 commit");   
       conn.commit();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (fis != null) {
            fis.close();
        }
        if (conn != null && !conn.isClosed()) {
            conn.close();
        }
    }
}

}

+2  A: 

This external discussion thread indicates that it may be a jdbc driver issue. They recommend updating the oracle jdbc thin drivers.

Andreas_D