title: How to solve bad sql grammar error with Spring JDBC?
body: <p>I'm using PostgreSQL with Spring JDBC. Everythig building with Gradle:</p>
  
  <pre><code>dependencies {
      compile("org.springframework.boot:spring-boot-starter-web")
      compile("org.springframework:spring-jdbc")
      compile("postgresql:postgresql:9.0-801.jdbc4")
      compile("com.h2database:h2")
      compile("com.googlecode.json-simple:json-simple:1.1")
      testCompile("junit:junit")
  }
  </code></pre>
  
  <p>Here is code fragment where I got exception:</p>
  
  <pre><code>String sql = "INSERT INTO " + dbname + " (:fields) VALUES (:values)";
  MapSqlParameterSource parameters = new MapSqlParameterSource();
  parameters.addValue( "fields", fieldsObj.keySet().toArray() );
  parameters.addValue( "values", fieldsObj.values().toArray() );
  count = jdbcTemplate.update( sql, parameters );
  </code></pre>
  
  <p>I get this error:</p>
  
  <blockquote>
    <p>PreparedStatementCallback; bad SQL grammar [INSERT INTO test (?, ?, ?) VALUES (?, ?, ?)]; nested exception is org.postgresql.util.PSQLException</p>
  </blockquote>
  
  <p>I've tried to convert array into string with values, divided by commas, but this gave me same error. What should I do? Or, if you have better ideas what to use, to build custom queries, please, post this idea in comments.</p>