title: Convert Java String to PostreSQL character varying («mpaa_rating»)?
body: <p>I'm writing a Java method that searches <a href="https://www.postgresqltutorial.com/postgresql-sample-database/" rel="nofollow noreferrer">the Postres sample 'DVD Rental' database</a> table for «films» based on their «mpaa_rating» datatype in the «rating» column. </p>
  
  <pre><code>public static void rechercheRating() {
  
          System.out.println("======= Ratings menu =========");
          System.out.println("\t 'G' ");
          System.out.println("\t 'PG' ");
          System.out.println("\t 'PG-13' ");
          System.out.println("\t 'R' ");
          System.out.println("\t 'NC-17' ");
          System.out.println("Entrez le rating désiré :");
          String userInput = sc.nextLine().toUpperCase(); 
          try {
              int foovalue = 10;
  
              PreparedStatement st = conn.prepareStatement("SELECT title, rating FROM film WHERE (rating = ?);");
  
              st.setString(1, userInput);
  
              ResultSet rs = st.executeQuery();
              System.out.printf("%-20s %-15s\n", "Film", "Rating");
  
              while (rs.next()) {
  
                  System.out.printf("%-20s %-15s\n", rs.getString(1), rs.getString(2));
  
              }
              rs.close();
              st.close();
          } catch (SQLException ex) {
              Logger.getLogger(DVDrental.class.getName()).log(Level.SEVERE, null, ex);
          }
  
      }//rechercheRating
  </code></pre>
  
  <p>The problem is the «mpaa_rating» is not a String datatype. The error I'm getting in my IDE is </p>
  
  <blockquote>
    <p>"org.postgresql.util.PSQLException: ERROR: operator does not exist:
    mpaa_rating = character varying"</p>
  </blockquote>
  
  <p>and</p>
  
  <blockquote>
    <p>"Hint: No operator matches the given name and argument type(s). You
    might need to add explicit type casts."</p>
  </blockquote>
  
  <p>How to convert a Java String to an Postres character varying?</p>