Reputation: 112
I'm using the following code to upload files into database the code is working fine with images where as for other files it is not working i'm posting stack trace at last.
My second value is a blob
String strFilePath = null;
Hashtable<Object,Object> fileTable = null;
InputStream input = null;
CosUploadFile file = null;
fileTable = multiPartFormData.getFiles();
file = (CosUploadFile)fileTable.get("filepath");
input =file.getInpuStream();
prepare = connection.prepareStatement("insert into all_files values(?,?,?)");
prepare.setString(1, strFileSplit[0]);
prepare.setBinaryStream(2,input);
prepare.setString(3,strFileSplit[1]);
prepare.execute();
Error :
J2CA0206W: A connection error occurred. To help determine the problem, enable the Diagnose Connection Usage option on the Connection Factory or Data Source.
J2CA0056I: The Connection Manager received a fatal connection error from the Resource Adapter for resource datasource. The exception is: java.sql.SQLRecoverableException: Io exception: Connection reset by peer: socket write error:java.net.SocketException: Connection reset by peer: socket write error
com.ibm.websphere.ce.cm.StaleConnectionException: Io exception: Connection reset by peer: socket write error
this is the stack trace while i'm trying to upload a doc file. What should I do Regarding this.
Edit: the following is my connection code
DBConnect dbConnect = new DBConnect();
Connection connection = dbConnect.connect();
DbConnect Class
public Connection connect()
{
Connection con = null;
try
{
InitialContext context = new InitialContext();
DataSource datasource = (DataSource)context.lookup("datasource");
con = datasource.getConnection("TRAIN2012", "xyz123");
return con;
}
Upvotes: 0
Views: 602
Reputation: 14731
Try with the following, however it is always better to store images in file system and store the location of the file in database. Lengthy discussions about this can be found here.
FileInputStream fis = null;
File image = new File("\\yourpath\test.PNG");
fis = new FileInputStream(image);
prepare.setBinaryStream(2,fis,(int)image.length());
prepare.execute();
Upvotes: 1