title: How to write generic mysql query in java
body: <p>I had tried a Query in generic Way i.e; i want to send data from one table to another table in generic way and my query is:</p>
  
  <pre><code>    Statement mystmt=myConn.createStatement();
  
      ResultSet rs = mystmt.executeQuery("SELECT * FROM empdetails");
       ResultSetMetaData rsmd = rs.getMetaData();
       int columnCount=rsmd.getColumnCount();
       int i=1,j=1;
       while(j&lt;=columnCount &amp;&amp; i&lt;=columnCount )
       {
           arr1[i]= rsmd.getColumnName(j);
           System.out.println(arr1[i]);
           i++;
           j++;
       } 
       int k=1;
  
       System.out.println(mystmt.executeUpdate("insert into table2(srccol_name,srccol_data)select 'empno',"+arr1[k]+" from empdetails"));  
  </code></pre>
  
  <p>And Here the problem is in srccol_name (i.e;'empno'), i had hardcoded the columnName.
  can anybody give solution for that.</p>