AbhiN
AbhiN

Reputation: 650

How to combine 2 parameters in Prepared statement

I want to convert below java Statement into PreparedStatement combining 2 parameters i.e. input1 and input2. How to do that?

   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) {

        }
    }

Upvotes: 1

Views: 208

Answers (1)

Eran
Eran

Reputation: 393771

Something like this?

String sql = "select * from veracodetable where output = ?";
PreparedStatement statement = con.prepareStatement(sql);
statement.setString(input1+input2);
statement.executeQuery();
rs = s.getResultSet();

Of course the PreparedStatement would have just one parameter, as you can see.

Upvotes: 2

Related Questions