Link to home
Start Free TrialLog in
Avatar of princehyderabad
princehyderabad

asked on

Arrange my Servlet code

Hi,

I'm new prg. Need a correct logic help. I have the servlet which is working fine.  Using org.apache.commons.fileupload to upload files.
 
WHAT IS PROBLEM:  If I try to upload large files eg. 100MB plus , I'm getting SQL error of 'Broken Pipe" It may be because my java code close loop only after upload is done and till then SQL connection is open.

WHAT CAN YOU DO: May be help to re-arrange my code so that all SQL happens in loop without having to wait till file upload. Plus hv my upload code separate from it.

---------My code----------------
...
DiskFileUpload upload = new DiskFileUpload();
List items = upload.parseRequest(req);
Iterator iter = items.iterator();
Map map = new HashMap();
while (iter.hasNext()) {
                                FileItem item = (FileItem) iter.next();
if (item.isFormField()) {  // some code ... }
 else
   {
     File cfile=new File(item.getName());
     <!-- Calling Stored Prodecure-1 (SP1)  to write to DB -->                  
     <!-- If user submited "a.txt" and "b.txt" to upload. Above SP1 will write just file name to DB -->                                          
                        ResultSet rs2 = null;
                        String rpath = null;

                                    if (rs2 == null)
                                    {
<!-- Calling Stored Prodecure-2 (SP2)  to get Path to write/upload on server  -->                          
<!-- This Path is generated by DB only after inserting file name to it
       In this case say 1st "a.txt" is write to DB in above SP1. Then..
       Path is generated say /hello/files/
       So I assigned this path to 'rpath' ie rpath = /hello/files/        -->
                                    }                  
<!-- Uploading the file on linux using that path  -->
File path = new File(rpath);                                                                  
File tosave=new File(path,cfile.getName());
item.write(tosave);
 }

Thanks for you time.
ASKER CERTIFIED SOLUTION
Avatar of achilka
achilka

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of princehyderabad
princehyderabad

ASKER

Excellent !!! Thanks a lot...