2011-12-23 70 views
0

我存儲在我的數據庫中的文件路徑:存儲文件路徑扔掉「」

selecteddestinationfilepath = selectedPfile.getPath(); 
. 
. 
. 
state.execute("INSERT INTO "+tablename+" (filename,filepath) VALUES ('"+theselecteddestinationname+"','"+theselecteddestinationfilepath+"')"); 

但是,當它被保存到數據庫中,它拋出了所有的「\ 「

所以不是D:\Programs\Rynmag181 -TFCD:ProgramsRynmag181 -TFC

我怎麼能解決呢?

+0

是在你的字符串中跳過的斜槓嗎? – martincarlin87 2011-12-23 12:09:48

+1

無論如何你需要解決這個問題,你知道你甚至可以在Windows上使用正斜槓嗎? – ThiefMaster 2011-12-23 12:21:23

回答

5

使用PreparedStatement的,與VALUES(?, ?)setParam(1, thesel...);setParam(2, ...)

這也可以防止SQL注入和做幾種形式逸出。

+0

輝煌,謝謝。 – mrbunyrabit 2011-12-23 13:32:40