从数据库中导入的字符串有引号("),想再次使用字符串查询数据库

Imported String from Database has quotes("), want to use String to Query Database again

所以我有一个脚本可以检索一段时间内在产品上使用过的项目列表。我们的数据库是 'jerry-rigged',可以这么说,我们没有将这些项目列为它们的代码,而是通过描述列出。我可以 运行 通过我们数据库中的另一个 table 这个描述来检索项目代码,但是我 运行 遇到了一个问题,其中的项目有双引号,比如 '2" Self Tapping Screw',其中双引号导致我的查询出现问题。以下是我遇到的问题行:

String description = resultSet.getString(1); //description = "2" Self Tapping Screw
String sql = "Select itemcode from database.table where description " 
    + "= \"" + description + "\";

如何用正则表达式字符替换这些双引号?我试过了

description = description.replace("\"","\"");

但我不认为我做对了,因为它只是将每个 '"' 更改为 "\"。

使用PreparedStatement:

Connection conn = DriverManager.getConnection("<Your connection string>");
String sql = "Select itemcode from database.table where description = ?";
PreparedStatement prep = con.prepareStatement(sql);
prep.setString(1,  resultSet.getString(1));
prep.executeUpdate();

这比自己尝试转义字符串要安全得多。