I am trying to insert values into my postgres database
url:"jdbc:postgresql://"+SERVER_NAME+":"+PORT_NUMBER+"/"+DATABSE_NAME,DATABASE_UN,DATABASE_PASS
I am able to read from the database. But when I write to database (no exceptions) there are no rows inserted to postgres database:
sqlQuery = "INSERT INTO tmp_recommend (id, v1, v2, v3, timestamp, v4, v5) VALUES("
+ "\""+ID+"\", "
+ "\""+value1+"\", "
+ "\""+value2+"\", "
+ value3+", "
+ new Timestamp((new Date().getTime()))+", "
+ "\"value4\", "
+ "\"value5\" "
+ ")";
st.executeUpdate(sqlQuery);
NOTE - I tried the following but didn't help:
- Change autocommit setting for database
If I try to do manual commit by conn.commit() it throws an exception
org.postgresql.util.PSQLException: Cannot commit when autoCommit is enabled
catch. Show more of your code, please. I don't know what the types of the values are, but that time stamp value, since you are using a plain statement rather than a prepared statement, is supposed to be quoted but isn't. And quotes in SQL are single quotes - double quotes are only placed around identifiers which are case sensitive. So the quotes you have aroundvalue1andvalue2are also incorrect.PreparedStatementis the only sane approach.