My java program collects a file path from a text field:
pathField.getText();
And inserts the results to my database (phpMyAdmin). However, it doesn’t seem to include the backslashes().
EG – C:UsersSteveDesktop
The FilePath field in the database is set to “Text”.
I have tested the pathField.getText() in a System.out statement, and it prints with the backslashes.
Statement st = (Statement) conn.createStatement();
String query_to_update = "INSERT INTO `evidence_db`.`mcases` ("
+ "`PID`,"
+ " `FilePath`) "
+ "VALUES ("
+ "DEFAULT,"
+ " '" + pathField.getText() + "');";
System.out.println("Query: " + query_to_update);
int val = st.executeUpdate(query_to_update);
Please note that I have edited the above code, so there might be minor errors.
you should use prepared statement to avoid this kind of errors
so in your case