在 Java 中使用 GUI 将文件上传到 Oracle 数据库的好例子

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5521922/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 23:14:04  来源:igfitidea点击:

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

javadatabaseoracleswingfile

提问by Amir

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?

我正在寻找一个很好的例子,在 Java 中向/从 Oracle 数据库上传和下载文件以获得想法。如果你们中有人知道一个很好的例子,你能帮助我吗?

回答by sfrj

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

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