Zoyinc
  • Home
  • Contact
  • Categories
    • CD Archiving
    • GIMP
    • Linux
    • MythTV
    • Open Media Vault
    • Technology
    • VMware
    • WordPress
    • YouTube
  • About


Problems with single quotes, JSP and PostgreSQL

By

Tony

,

August 16, 2013

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.

 

Related

DNS problems, email notifications not being sent
Date Problems Converting A Dictionary To JSON
Resetting a PostgreSQL root password
YankIt – Extract from Oracle using JDBC including blobs
Recent

  • AlmaLinux GUI – no taskbar or application shortcuts

    AlmaLinux GUI – no taskbar or application shortcuts

  • AlmaLinux 9.5 base VM

    AlmaLinux 9.5 base VM

  • Reset Kodi thumbnails

    Reset Kodi thumbnails

  • Set default settings values in Kodi skins

    Set default settings values in Kodi skins

  • Add/Remove/Reset music/video libraries in Kodi

    Add/Remove/Reset music/video libraries in Kodi

  • Zoyinc Kodi skin on Sony TV

    Zoyinc Kodi skin on Sony TV

  • [L] – WordPress UAM Locked Post

    [L] – WordPress UAM Locked Post

  • Import Pictures and Videos – images not previewed

    Import Pictures and Videos – images not previewed

  • Find My Train

    Find My Train

  • WordPress style name not visible

    WordPress style name not visible

About Zoyinc

  • Contact Us
  • Zoyinc Disclaimer
  • Google Search Console
  • Privacy Policy
  • Site Statistics
  • Login

Apache Auckland Backup CD CentOS Centos7 Children Configuration Debian Error ESX ESXi Fedora Firewall Install Josh Kids Kodi Linux MariaDB MySQL MythTV New Zealand OKD OMV Open Media Vault OpenShift PHP Player Python RAID RedHat Red Hat Rip School Setup SMB SonicWALL Spark tags Train Trains VLAN VM VMware Weaver Windows WordPress YouTube

Powered by

This site is licensed under a Creative Commons Attribution 4.0 International License.