I am developing an application where I have to open documents from the application. I have to save the path of the file to the sql database. The column in sql to which file path is inserted is of type VARCHAR(255).
If the path of a file is C:\Users\UPS21120\Downloads\doc1.pdf
,it being saved in the database as as C:UsersUPS21120Downloadsdoc1.pdf
(where are the backslashes in the saved path?).
When i retrieve this path to open the file doc1.pdf
, I am getting an exception which says that doc1 does not exist.Following is the code I used to save the path. Please help.
JFileChooser fc = new JFileChooser();
returnVal = fc.showOpenDialog(view_doc.this);
File file1=fc.getSelectedFile();
if (returnVal == JFileChooser.APPROVE_OPTION) {
String str = "INSERT INTO document(doc_path) VALUES ('"+file+"')";
// open connection..execute query etc--works fine
}