how to save image path to sql database in java

匆匆过客 提交于 2019-12-13 06:42:45

问题


I have to save the image path chosen by jfilechooser to sql database and load that image every time from that sql path. Im using preparedStatment . But I got the path saved in sql database without "\" . 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();
        }

回答1:


Standard solution is Escape.

Quick solution is replace slash with some special character, while change it back later.



来源:https://stackoverflow.com/questions/23234137/how-to-save-image-path-to-sql-database-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!