• Post Reply Bookmark Topic Watch Topic
  • New Topic

write into pdf file using binary data stored in database  RSS feed

 
nitin sharma nitin
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


(Edit: I added code tags so the code would be more readable -- Paul C)










. please tell me how to write some more content into pdf through before save onto disk
 
Pete Nelson
Ranch Hand
Posts: 147
Debian Eclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You would probably need some sort of library for creating PDF documents. Googling "Java PDF API" results in a number of commercial products (although many are still free of charge to use).

A couple of pointers on your servlet and databases, though. All the code inside your doGet method is going to be run with every request. Typically when you have a resource like a database driver, you only want to initialize once, and not with every request. Take a look at the Servlet.init(...) method -
If you must declare a database driver in this way, no sense re-declaring it with every request.

Another problem is that you're declaring the Connection as a member of your servlet. Then with each request, you're re-opening it, and never closing it. This will quickly lead to memory leaks and other performance problems. In general, your database connection should not outlive the request.


 
Paul Clapham
Sheriff
Posts: 22690
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pete Nelson wrote:A couple of pointers on your servlet, though. All the code inside your doGet method is going to be run with every request. Typically when you have a resource like a database driver, you only want to initialize once, and not with every request. Take a look at the Servlet.init(...) method -


"Initialize once"... yes, that's true. But in real life you would get a database connection from a connection pool configured into the servlet container. Having a database connection which belongs to a specific servlet also has its own problems as a design: it isn't thread-safe and it doesn't scale to the case where several servlets need database connections.
 
Pete Nelson
Ranch Hand
Posts: 147
Debian Eclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:But in real life you would get a database connection from a connection pool configured into the servlet container.


You bet - using DataSources & JNDI is certainly the better approach. There were a lot of issues with the code provided, but I had to stop somewhere! I actually had a reply about three times the length, and just decided it was too much to hit the guy with all at once (Especially when his question was really about creating a PDF).
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!