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.