문제

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top