2011-12-23 3 views
0

내가 내 데이터베이스의 파일 경로를 저장하고 "\"멀리 던져 :이 데이터베이스에 저장 될 때저장 파일 경로

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

는하지만 멀리 던져 모든 "\ "

그래서 대신

D:\Programs\Rynmag181 -TFC D:ProgramsRynmag181 -TFC

나는 어떻게 고칠 수는?

+0

은 문자열에서 이스케이프 된 슬래시입니까? – martincarlin87

+1

어쨌든 문제를 해결해야하지만 Windows에서도 슬래시를 사용할 수 있다는 것을 알고 있습니까? – ThiefMaster

답변

5

이것은 또한 SQL 주입을 방지하고 탈출의 여러 형태를 수행, VALUES(?, ?)setParam(1, thesel...);setParam(2, ...)PreparedStatement의을 사용합니다.

+0

훌륭해, 고마워. – mrbunyrabit