我正在使用以下代码将文件上传到数据库中,该代码与图像一起工作正常,而对于其他文件不起作用,我最后发布了堆栈跟踪。
我的第二个值是 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();
错误 :
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
这是我尝试上传 doc 文件时的堆栈跟踪。对此我该怎么办。
编辑:以下是我的连接代码
DBConnect dbConnect = new DBConnect();
Connection connection = dbConnect.connect();
数据库连接类
public Connection connect()
{
Connection con = null;
try
{
InitialContext context = new InitialContext();
DataSource datasource = (DataSource)context.lookup("datasource");
con = datasource.getConnection("TRAIN2012", "xyz123");
return con;
}