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 ]