title: Dynamic column in sql/jdbc query
body: <p>I am a student of Computer Science. Now I am working on a project with jdbc. I have to table in database - <code>USER</code>, <code>ROLE</code>. </p>
  
  <p>Where each <code>USER</code> have a one or multiple <code>ROLE</code>. I save the <code>ROLE.ID</code> (primary key or <code>ROLE</code>) in <code>USER.ROLE_ID</code> column.</p>
  
  <p>In java code level I have two entity class also - <code>User.java</code> and <code>Role.java</code>. I can make the simple SQL query with joining these tables. </p>
  
  <p>Please see the following queries -  </p>
  
  <p><strong>1.</strong> Selecting <code>USER.NAME</code> and <code>ROLE.NAME</code> for <code>USER.NAME='admin'</code> -   </p>
  
  <pre><code>SELECT USER.NAME, ROLE.NAME FROM USER, ROLE
     WHERE USER.ROLE_ID = ROLE.ROLE_ID
     AND USER.NAME='admin';
  </code></pre>
  
  <p><strong>2.</strong> Selecting <code>USER.ID</code> and <code>ROLE.ID</code> for the <code>USER.NAME='admin'</code> -   </p>
  
  <pre><code>SELECT USER.ID, ROLE.ID FROM USER, ROLE
     WHERE USER.ROLE_ID = ROLE.ROLE_ID
     AND USER.NAME='admin';  
  </code></pre>
  
  <p>I have to make 2 different queries <strong>ONLY</strong>  for the different columns I am selecting. Here most of the query is same. My question is can I do something so that I can dynamically select different (in first case - USER.NAME, ROLE.NAME and Second case USER.ID, ROLE.ID) types of column using a single query? </p>