• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

image insertion problem

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I try to store a image file into Oracle database and i use the below code while i run this i get the following error:

output:

Hello1
Hello2
Hello3
The Exception in tryjava.sql.SQLException: Io exception: Connection reset by peer: socket write error

The code is:
package com.hewitt.sun.cds;
import java.io.File;
import java.io.FileInputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.logging.Logger;

import com.hewitt.mb.common.utilities.AppVariables;
import com.hewitt.mb.common.utilities.DBUtil;

public class TestImage {

static Logger logger = Logger.getLogger("com.hewitt.marriott.cds");

static int i = 0;
static Connection lConn = null;
static Statement stmt = null;
static ResultSet rs = null;
static DBUtil db;
public static void main(String[] args)throws Exception {

String val = "config/Marketlink.props";
AppVariables.load(val);

File file=null;
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

lConn = DriverManager.getConnection(AppVariables.get("ConnectionString"),AppVariables.get("OracleUser"),AppVariables.get("OraclePwd"));


try
{

file = new File("C:\\Sunset.jpg");


System.out.println("Hello1");
FileInputStream fis = new FileInputStream(file);
System.out.println("Hello2");
PreparedStatement pstmt = lConn.prepareStatement(
"insert into ar1 values('im19',?)");
pstmt.setBinaryStream(1, fis, (int)file.length());
System.out.println("Hello3");
pstmt.executeUpdate();

System.out.println("Hello4");

pstmt.close();
fis.close();
System.out.println("Hello5");




}
catch(Exception e){
System.out.println("The Exception in try"+e);
}


}

}


The table has two columns image_name which is varchar type
The content column which is of type BLOB.

But when i run this program the insert command insert the valu im19
in the IMAGE_NAME field but not the image file..


I KNOW THERE IS NOTHING WRONG WITH THIS PROGRAM.

[made subject all lowercase]
[ November 13, 2006: Message edited by: Jeanne Boyarsky ]
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could you be a hitting a timeout?
 
Arun Prasath
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes, when i searched in Google they have mentioned that it was due to time out.But while my friend working in the same workstation while use the same connection he works fine and the database inserts the image

Could you find any other specific reason for this error...

Thanks
reply
    Bookmark Topic Watch Topic
  • New Topic