java – How to save a PDF file in the database and make it available for download?


I'm developing a web application using PlayFramework, and I need a file that will be a kind of guide (documentation) for users who will use my application to download or view it in the browser in order to guide them in handling the platform. I'm using the local database for now, H2 to store my data. How do I save this pdf document in my database so that I can later make it available for download or viewing?

Here is one of the classes of the bank, where the pdf file could be inserted right here.

public class Auditoria extends Model{

public String usuario;
public String action;
public String controller;
public Date data;   

public Auditoria(){ = new Date();


You can save any file to an sql database using a varbinary(max) column.

Just create a method that converts the file to binary and save it to the DB, and then to read it just do the reverse.

Scroll to Top