Java – Good example for upload file to Oracle database with GUI in Java


I am looking for a good example of upload & download file to/from Oracle database in Java to get idea. Would you please help me if any of you know a good example?

Best Solution

Here for upload:

public class FileToDatabase {
    public static void main(String[] args) throws Exception {
            String fileName = "C:/input.txt";
            File file = new File(fileName);
            FileInputStream fis = new FileInputStream(file);
            Connection conn = DriverManager.getConnection(
                            "jdbc:mysql://localhost:3306/test", "root", "root");
            PreparedStatement pstmt = conn
                            .prepareStatement("insert into file( file, file_data) values ( ?, ?)");
            pstmt.setString(1, file.getName());
            pstmt.setBinaryStream(2, fis, (int) file.length());

Here for download

I found a good piece of code for file downloading from an application server, (in the link below). If you are going to use a web app, you could cache the file from the database into the application before the download.(Im interested in what other thinks about this alternative)