title: Setting PostgreSQL enums using a JDBC ResultSet
body: <p>I'm trying to copy data from a MySQL database to an equivalent PostgreSQL database, doing a load/insert through Java using JDBC. I get this error whenever I try to copy an enum column:</p>
  
  <blockquote>
    <p>org.postgresql.util.PSQLException: ERROR: column "mycol" is of type mytable_mycol_enum but expression is of type character varying<br>
      Hint: You will need to rewrite or cast the expression.<br>
      Position: 194</p>
  </blockquote>
  
  <p>The Java code (simplified and anonymized):</p>
  
  <pre><code>Class.forName("com.mysql.jdbc.Driver").newInstance();
  Connection mysqlConn = DriverManager.getConnection(
      "jdbc:mysql://localhost/mysqldb", "user", "pass");
  Class.forName("org.postgresql.Driver").newInstance();
  Connection pgConn = DriverManager.getConnection(
      "jdbc:postgresql://othercomp/pgdb", "user", "pass");
  
  Statement selStatement = mysqlConn.createStatement();
  ResultSet selSet = selStatement.executeQuery("SELECT * FROM mytable");
  
  Statement insStatement = pgConn.createStatement(
      ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
  Resultset insSet = insStatement.executeQuery("SELECT * FROM mytable WHERE 0=1");
  insSet.moveToInsertRow();
  
  while(selSet.next())
  {
      ResultSetMetaData metaData = selSet.getMetaData();
      for (int i = 1; i &lt;= metaData.getColumnCount(); i++)
      {
          String colName = metaData.getColumnName(i);
          Object obj = selSet.getObject(colName);
          insertSet.updateObject(colName, obj);
      }
      insertSet.insertRow();
  }
  </code></pre>
  
  <p>This works fine for tables without an enum column, but </p>
  
  <p>In MySQL I have a column <code>mycol</code> of type <code>enum('A','B','C')</code></p>
  
  <p>In PostgreSQL I have <code>mycol</code> of type <code>mytable_mycol_enum</code> with <code>CREATE TYPE mytable_mycol_enum AS ENUM ('A','B','C')</code></p>
  
  <p>How do I set the enum value?</p>