0

次のコードを使用してファイルをデータベースにアップロードしていますが、コードは画像で正常に動作していますが、他のファイルについては動作していません。最後にスタック トレースを投稿しています。

私の2番目の値はブロブです

   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

これは、ドキュメント ファイルをアップロードしようとしているときのスタック トレースです。これについてはどうすればいいですか。

編集:以下は私の接続コードです

DBConnect dbConnect = new DBConnect();
Connection connection = dbConnect.connect();

DbConnect クラス

  public Connection connect() 
    {   
    Connection con = null;
    try
    {
    InitialContext context = new InitialContext();
    DataSource datasource = (DataSource)context.lookup("datasource");
    con = datasource.getConnection("TRAIN2012", "xyz123");
    return con;
    }
4

1 に答える 1

1

以下を試してみてください。ただし、画像をファイル システムに保存し、ファイルの場所をデータベースに保存することをお勧めします。これに関する長い議論は ここにあります。

FileInputStream fis = null;

File image = new File("\\yourpath\test.PNG");
fis = new FileInputStream(image);
prepare.setBinaryStream(2,fis,(int)image.length());
prepare.execute();
于 2012-11-19T10:56:23.580 に答える