• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

image insertion problem

 
Arun Prasath
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • 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 ]
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34218
341
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you be a hitting a timeout?
 
Arun Prasath
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic