I have a small web app that updates various PostgreSQL tables. I recently updated from Fedora 14 to Fedora 18 and as a result PostgreSQL was updated and I expect JDK as well.
All of a sudden I notice I couldn’t update rows which contained strings when the strings had single quotes in them.
I just got back the cryptic error message:
ERROR: syntax error at or near "\" at character 304
The JSP code looks like:
Connection conn; String connectionString="jdbc:postgresql://" + dbServer + ":" + dbPort + "/" + dbInstance; Statement s; int lenstr = newdescription.length(); String prtlenstr = Integer.toString(lenstr); queryString = "update knowbase set "+(char)34+"DESCRIPTION"+(char)34+" = ?, "+(char)34; queryString += "SUBJECT"+(char)34+" = ?, "+(char)34+"PRODUCTID"+(char)34+" = ?, "; queryString += (char)34+"PRIVATE"+(char)34+" = ?"; queryString = queryString + " where rtrim("+(char)34+"TIMESTAMP"+(char)34+") = rtrim('" + tstamp + "')"; queryStringLongSave = queryString; try { DriverManager.registerDriver(new org.postgresql.Driver()); conn=DriverManager.getConnection(connectionString, dbUserName, dbPassword ); PreparedStatement pstat = conn.prepareStatement( queryString ); java.io.ByteArrayInputStream bais = null; bais = new java.io.ByteArrayInputStream(newdescription.getBytes()); pstat.setAsciiStream(1, bais, bais.available()); pstat.setString(2, newsubject); pstat.setInt(3, newproductid); pstat.setInt(4, newprivate); pstat.executeUpdate(); } catch(Exception e){ updateExeception = "<br>Error results.jsp e =" + e.getMessage() + "<br><br>"; };
Resolution
After a very long time of searching and a fair share of guesswork it turned out all I needed to do was upgrade my PostgreSQL JDBC drivers to the latest to match the DB version.