Reputation: 75
I am trying to store to my MySQL database the path of a file I uploaded to Tomcat. I have stored the path to a string named filepath, but when I execute the program, I get this error:
"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ':\Users\Nick\Desktop\bot.png)' at line 1 " A part of the code I used:
String fileName = fi.getName();
String contentType = fi.getContentType();
boolean isInMemory = fi.isInMemory();
long sizeInBytes = fi.getSize();
// Write the file
if( fileName.lastIndexOf("\\") >= 0 ){
file = new File( filePath +
fileName.substring( fileName.lastIndexOf("\\"))) ;
}else{
file = new File( filePath +
fileName.substring(fileName.lastIndexOf("\\")+1)) ;
}
I suppose the problem has to do with the format of the path, but I am pretty new to java, so I would really appreciate some help. Thank you in advance.
Upvotes: 0
Views: 850
Reputation: 2196
path = path.replaceAll((char) 92 + "" + (char) 92, (char) 47 + "");
Upvotes: 0
Reputation: 972
Either use double backslashes to escape or forward slash, or better still prepared statements.
Upvotes: 2