Java 在vaadin中将文件保存到数据库

Java 在vaadin中将文件保存到数据库,java,sql,postgresql,upload,vaadin,Java,Sql,Postgresql,Upload,Vaadin,您好,我正在尝试使用vaadin将文件保存到我的数据库中。我有一个web应用程序,允许用户上传文件,到目前为止,文件上传到我的文件系统。以下是我的上传代码: public class FileUploader implements Receiver, SucceededListener { File file; public OutputStream receiveUpload(String fileName, String mimeType) {

您好,我正在尝试使用vaadin将文件保存到我的数据库中。我有一个web应用程序,允许用户上传文件,到目前为止,文件上传到我的文件系统。以下是我的上传代码:

public class FileUploader implements Receiver, SucceededListener {
        File file;

        public OutputStream receiveUpload(String fileName, String mimeType) {
            FileOutputStream fos = null;

            try {
                file = new File("C:\\Documents and Settings\\ABDEN00U\\Desktop\\tmp\\" + fileName);
                fos = new FileOutputStream(file);   
            } catch (final java.io.FileNotFoundException e) {
                new Notification("Could not open file", e.getMessage(), Notification.TYPE_ERROR_MESSAGE.ERROR_MESSAGE).show(Page.getCurrent());
                return null;
            }

            return fos; 
        }

        @Override
        public void uploadSucceeded(SucceededEvent event) {
            // TODO Auto-generated method stub
            file_upload.setVisible(true);
            file_upload.setSource(new FileResource(file));
        }

我要做的是抓取文件并将其转换为字节数组,然后将其上载到我的postgres数据库。

上载成功的
方法中,您可以将
文件
转换为
字节[]

怎么会?”这是一个可能的解决办法

然后将
字节[]
存储到数据库中的blob字段中