narayanabhilash 0 Newbie Poster

Code for Upload....

        strLegalDocId = strMerchantId + strLegalStruct;
        String strSql = "{call Insert_FileData(?, ?, ?, ?, ?, ?,?)}";
        objCst = objCon.prepareCall(strSql);
        objCst.setString(1, strMId);
        objCst.setString(2, strLS);
        objCst.setString(3, strFieldId);
        objCst.setString(4, strFileName);
        objCst.setString(5, strLDId);
        bFileSize = inpStream.available();
        objCst.setBinaryStream(6, inpStream, bFileSize);
        objCst.registerOutParameter(7, Types.CHAR);
        objCst.executeUpdate();
        strStatus = objCst.getString(7);
        System.out.println("strStatus : " + strStatus);

Code for Download .......

        strSql = "SELECT photo FROM image WHERE photo_Id = '" + strPhotoId + "'";
        refCon = ConnectionManager.getConnection();

        refSt = refCon.createStatement();
        refRS = refSt.executeQuery(strSql);
        String imgLen = "";
        if (refRS.next()) {
            imgLen = refRS.getString("legal_document");
        }
        refRS=null;
        refRS = refSt.executeQuery(strSql);
        if (refRS.next()) {
            int len = imgLen.length();
            byte[] rb = new byte[len];
            InputStream readImg = refRS.getBinaryStream("legal_document");
            int index = readImg.read(rb, 0, len);
            response.reset();
            response.setContentType("image/jpg");
            response.getOutputStream().write(rb, 0, len);
            response.getOutputStream().flush();
        }