title: JDBC - Inserting an array variable into a PostgreSQL table
body: <p>I am trying to insert an array variable into the table. The code is shown below</p>
  
  <pre><code>import java.sql.Connection;
  import java.sql.DriverManager;
  import java.sql.ResultSet;
  import java.sql.Statement;
  
  class PostgreSQLJDBC {
  
      public static void main(String args[]) {
          Connection c = null;
          Statement stmt = null;
          Statement stmt1 = null;
          int id[] = new int[3];
          int no = 1;
          id[0] = 2;
          id[1] = 14;
          id[2] = 4;
          try {
              Class.forName("org.postgresql.Driver");
              c = DriverManager
                      .getConnection("jdbc:postgresql://localhost:5432/ass2",
                              "postgres", "post");
              c.setAutoCommit(true);
              System.out.println("Opened database successfully");
              stmt = c.createStatement();
              String sql1 = "INSERT INTO COMPANY (NO,ID) "
                      + "VALUES (7, id);";
              stmt1 = c.createStatement();
              stmt1.executeUpdate(sql1);
              stmt1.close();
              c.close();
          } catch (Exception e) {
              System.err.println(e.getClass().getName() + ": " + e.getMessage());
              System.exit(0);
          }
          System.out.println("Operation done successfully");
      }
  }
  </code></pre>
  
  <p>This code compiles <a href="https://stackoverflow.com/questions/48642761/how-to-insert-an-element-to-a-column-with-array-field">but gives an PSQLexception.</a></p>
  
  <p>Could someone please help in fixing this</p>