title: Get the metadata for prepared statement in java with MySql DB
body: <p>I want to fetch parameter name and parameter type of given prepared statement. I am using MySQL Database. But when I run my program it is throwing an error:</p>
  
  <pre><code>Exception in thread "main" java.sql.SQLException: Parameter metadata not available for the   given statement
  </code></pre>
  
  <p>at this line</p>
  
  <pre><code>String paramTypeName = paramMetaData.getParameterTypeName(param);
  </code></pre>
  
  <p>I don't know why this is happening. Please anybody help me if possible.</p>
  
  <p>Here's my code:</p>
  
  <pre><code>import java.sql.Connection;
  import java.sql.DriverManager;
  import java.sql.ParameterMetaData;
  import java.sql.PreparedStatement;
  import java.sql.Statement;
  
  public class Main {
    public static void main(String[] args) throws Exception {
      Connection conn = getMySqlConnection();
      Statement st = conn.createStatement();
  
      String query = "select * from survey where id &gt; ? and name = ?";
      PreparedStatement pstmt = conn.prepareStatement(query);
      ParameterMetaData paramMetaData = pstmt.getParameterMetaData();
      if (paramMetaData == null) {
        System.out.println("db vendor does NOT support ParameterMetaData");
      } else {
        System.out.println("db vendor supports ParameterMetaData");
        // find out the number of dynamic parameters
        int paramCount = paramMetaData.getParameterCount();
        System.out.println("paramCount=" + paramCount);
        System.out.println("-------------------");
        for (int param = 1; param &lt;= paramCount; param++) {
          System.out.println("param number=" + param);
          String paramTypeName = paramMetaData.getParameterTypeName(param);
          System.out.println("param SQL type name=" + paramTypeName);
        }
      }
      pstmt.close();
      conn.close();
    }
  
  public static Connection getMySqlConnection() throws Exception {
      String driver = "com.mysql.jdbc.Driver";
      String url = "jdbc:mysql://localhost:3306/mydb";
      String username = "root";
      String password = "";
      Class.forName(driver);
      Connection conn = DriverManager.getConnection(url, username, password);
      return conn;
    }
  
  }
  </code></pre>