Win a copy of Pragmatic AI this week in the Artificial Intelligence forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Problem in Uploading Text File  RSS feed

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All


I am using below JSP code to upload the txt file with 231KB ,
program is working but it upload some lines /half of the file
Please help me tackle the problem


(edited to add code tags)
 
Bartender
Posts: 1844
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok major things wrong.

#1 - you have java code in a jsp. Java code belongs in a java class.
#2 - you're reinventing the square wheel. Go look up the apache commons fileupload component Use that instead of interpreting the input stream
#3 - Your program is open to sql injection. Use prepared statements rather than building up sql strings
#4 - Use a pooled JNDI datasource for obtaining database connections from

 
Nilesh Dalvi
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Sir,
Thanks For your reply ,
But i m new to JAVA please help me to change the source so that i can upload the full text file.

Now. this program upload the file but it taKES ONLY 500 rows in a table. Remaining part is not uploaded
What changes should be done in program to avoid this.


Thanks in advance.

Nilesh.
 
Sheriff
Posts: 23649
49
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My guess is that you aren't reading the entire upload. I don't see a loop there, so that's probably the problem.

However it's hard to read that code because it has JSP scriptlets embedded in it, so I can't say for sure. Don't put it in a JSP if you want it to be readable. And you do want it to be readable.

And it looks like you're trying to read the data and write it to a file somewhere, then read that file back so you can update the database. Is there any point in having that file, or did you just not know how to take the data and update the database directly? It would be easier if you used the Apache file upload package, then it would be quite clear how to read from the upload and update the database.

So in summary: Stefan has some good advice. Don't just ignore it because you think you can fix what you have there; it's better to get rid of most of that code and replace it by good code.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!