开发者

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. Wou开发者_如何学运维ld you please help me if any of you know a good example?


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);
            Class.forName("com.mysql.jdbc.Driver");
            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());
            pstmt.executeUpdate();
    }

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)

Link: http://www.daniweb.com/software-development/java/threads/154128

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜