简体   繁体   English

如何在Java中将图像路径保存到sql数据库

[英]how to save image path to sql database in java

I have to save the image path chosen by jfilechooser to sql database and load that image every time from that sql path. 我必须将jfilechooser选择的映像路径保存到sql数据库,并每次从该sql路径加载该映像。 Im using preparedStatment . 我正在使用prepareStatment。 But I got the path saved in sql database without "\\" . 但是我将路径保存在sql数据库中,没有“ \\”。 Here is part my code.. Please help me on this. 这是我的代码的一部分。请对此提供帮助。

    PreparedStatement ps = null;
    ResultSet rs = null;
    Connection conn = null;
conn = DBConnection.ConnectDB();

 try {
            JFileChooser choose = new JFileChooser();
            choose.showOpenDialog(null);
            File f = choose.getSelectedFile();
            if (f != null) {
                fileName = f.getAbsolutePath();

                String sql = "UPDATE addskin SET Path='" + fileName + "' WHERE Name='Assigned'";
                ps = conn.prepareStatement(sql);
                ps.execute();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

Standard solution is Escape . 标准解决方案是Escape

Quick solution is replace slash with some special character, while change it back later. 快速解决方案是用一些特殊字符替换斜杠,然后再将其改回来。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM