简体   繁体   中英

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. 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();
        }

Standard solution is Escape .

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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