This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes JDBC and the fly likes image insertion problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » JDBC
Bookmark "image insertion problem" Watch "image insertion problem" New topic
Author

image insertion problem

Arun Prasath
Ranch Hand

Joined: Aug 14, 2006
Posts: 30
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

Joined: May 26, 2003
Posts: 30580
    
154

Could you be a hitting a timeout?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Arun Prasath
Ranch Hand

Joined: Aug 14, 2006
Posts: 30
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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: image insertion problem