title: How to reflectively invoke PrepareStatement.set
body: <p>I'm trying to reflectively invoke the setXxx method of    com.mysql.jdbc.PreparedStatement using the following code. </p>
  
  <pre><code>String type = getJavaTypeFromMySqlType(); // this is "String"
  Class clazz = type.getClass(); // This is java.lang.String
  Method method = com.mysql.jdbc.PreparedStatement.class.getDeclaredMethod("set"+type, int.class, clazz);
  method.invoke(cnt, clazz.cast(pair.getValue())); 
  </code></pre>
  
  <p>The last line throws </p>
  
  <blockquote>
    <p>java reflection object is not an instance of declaring class</p>
  </blockquote>
  
  <p>What am I missing here? </p>