选择查询中的动态变量

时间:2019-02-05 14:30:37

标签: spring postgresql

我的请求中有一个来自产品的transactionReceipt变量,即product.gettransactionReceipt(),如何将此值发送到请求中的transactionReceipt? transactionReceipt是作为用户字段的json之一

// TODO check another users bought
if (!purchased.contains(product.getProductId())) {
  Statement st = conn.createStatement();
  String transactionReceipt = product.getTransactionReceipt();
  ResultSet rs = st.executeQuery("DECLARE transactionReceipt ; Select username from user WHERE  info -> 'purshasedProducts' ->> 'transactionReceipt' = 'transactionReceipt");

1 个答案:

答案 0 :(得分:0)

您可以改用PreparedStatement,并将transactionReceipt作为参数传递给它。喜欢:

PreparedStatement st = conn.prepareStatement("Select username from user WHERE  info -> 'purshasedProducts' ->> 'transactionReceipt' = ?");

String transactionReceipt = product.getTransactionReceipt();
st.setString(1, transactionReceipt);

ResultSet execute = st.executeQuery();