如何在Prepared语句中组合2个参数

时间:2017-11-12 14:17:19

标签: java prepared-statement

我想将以下java 语句转换为 PreparedStatement ,将2个参数组合在一起,即input1和input2。怎么做?

   public static void main(String[] args) {

        String input1="Hello";
        String input2="World";

        try {

            String sql = "select * from veracodetable where output = \'"  +input1 + input2+ "\'";
            statement = con.createStatement();
            statement.executeQuery(sql);
            rs = s.getResultSet();
        } 
        catch (Exception e) {

        }
    }

1 个答案:

答案 0 :(得分:2)

这样的东西?

public class PolazakAdapterRv extends RecyclerView.Adapter<PolazakHolder> {

private final Context context;
private List<Integer> list;

public PolazakAdapterRv(Context context) {
    this.context = context;
    this.list = new ArrayList<>();
}


public void setMap(List<Integer> list) {
    this.list = list;
}

@Override
public PolazakHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View view = LayoutInflater.from(context)
            .inflate(R.layout.rv_polazak, parent, false);
    return new PolazakHolder(view);
}

@Override
public void onBindViewHolder(PolazakHolder holder, int position) {
    holder.textViewPolazakHour.setText(list.get(position).toString());
}

@Override
public int getItemCount() {
    return list.size();
}

当然,String sql = "select * from veracodetable where output = ?"; PreparedStatement statement = con.prepareStatement(sql); statement.setString(input1+input2); statement.executeQuery(); rs = s.getResultSet(); 只有一个参数,如您所见。