I have a table with attributes id and name1,name2,name3.....name10, where all these ten names belong to the id.
id name1 name2 name3 name4 name5 name6 name7 name8 name9 name10
201 ijk lmn xyz abc efg hks dkm jjl dkn awt
202 mjl pan van slm tko kds jar slk dkf asd
Now I need to retrieve the id, whichever the name among 10 names was encountered. If it is a print statement, it would be very easy to increment the numbers using the loop by keeping the string "name" as it is. But how to do it when using the mysql statement? First of all is it even possible to pass the attribute name as a string?
eg: when passing string for where condition,
String uname=jf1.getText();
PreparedStatement stmt=conn.prepareStatement("Select * from staff where id = ?");
stmt.setString(1,uname);
ResultSet rs=stmt.executeQuery();
rs.next();
But when I need to check all attributes from name1 to name10, can it be like this?
String uname=jf1.getText();
PreparedStatement stmt=conn.prepareStatement("Select id from staff where ?=?");
for(int i=1;i<=10<i++)
stmt.setString(1,"name"+i);
stmt.setString(2,uname);
Where uname is given by user through text field.