【问题标题】:storing file path in mysql throws away "\"在mysql中存储文件路径会丢弃“\”
【发布时间】:2011-12-23 12:08:23
【问题描述】:

我在我的数据库中存储一个文件路径:

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

但是当它存储到数据库中时,它会丢弃所有的“\”

所以而不是D:\Programs\Rynmag181 -TFC 它的D:ProgramsRynmag181 -TFC

我该如何解决这个问题?

【问题讨论】:

  • 你的字符串中的斜杠是否被转义了?
  • 尽管您仍然需要解决问题,但您知道即使在 Windows 上也可以使用正斜杠吗?

标签: java mysql file netbeans insert


【解决方案1】:

使用PreparedStatement,带有VALUES(?, ?)setParam(1, thesel...); setParam(2, ...)

这也可以防止 SQL 注入并进行多种形式的转义。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-06
    • 2010-12-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多