1

I am currently working on fixing some SQL injection bugs in my project.

Here is my current sql string:

String sql = "select * from :table order by storenum";

Here is how I am setting the parameters:

SQLQuery query =  sess.createSQLQuery(sql).setParameter("table", table);

(table is a string that is passed in through a method)

Whenever I run the program I get something like this:

select * from ? order by storenum

1 Answer 1

2

You can't dynamically bind table names, only values, so you'll have to resort to string manipulation/concatenation to get the table name dynamically. However, you would probably want to escape it to avoid SQL Injections.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.