• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem in Uploading Text File  RSS feed

 
Nilesh Dalvi
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)
 
Stefan Evans
Bartender
Posts: 1836
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.
 
Paul Clapham
Sheriff
Posts: 22509
43
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!