Thread: Loggin SQL warnings in JDBC driver

Loggin SQL warnings in JDBC driver

From
Edson Richter
Date:
I've applyied both paths below to be able to print SQL Warnings when
loglevel=1 when working with JDBC 9.2.2 driver.
I did create this as separate driver compilation, because I don't want
the slowdown introduced in the addWarnings (that would affect
significantly my production servers).
Using this patch it is possible to get logged the RAISE NOTICE warnings
from triggers, among other warnings.


First patch:

---------------------------------------------------------------------------------------------------------------------------

# This patch file was generated by NetBeans IDE
# It uses platform neutral UTF-8 encoding and \n newlines.
--- <html>AbstractJdbc2Statement.java (<b>Nov 14, 2012 9:08:49
AM</b>)</html>
+++ <html><b>Current File</b></html>
@@ -745,6 +745,10 @@
       */
      public void addWarning(SQLWarning warn)
      {
+      if(connection.getLogger()!=null) {
+        connection.getLogger().log("Warning", warn);
+      }
+
          if (warnings == null) {
              warnings = warn;
              lastWarning = warn;


---------------------------------------------------------------------------------------------------------------------------


Second patch:

---------------------------------------------------------------------------------------------------------------------------

# This patch file was generated by NetBeans IDE
# It uses platform neutral UTF-8 encoding and \n newlines.
--- <html>AbstractJdbc2Connection.java (<b>Nov 14, 2012 9:08:49
AM</b>)</html>
+++ <html><b>Current File</b></html>
@@ -327,6 +327,9 @@
       */
      public void addWarning(SQLWarning warn)
      {
+        if(getLogger()!=null) {
+          getLogger().log("Warning", warn);
+        }
          // Add the warning to the chain
          if (firstWarning != null)
              firstWarning.setNextWarning(warn);


---------------------------------------------------------------------------------------------------------------------------


Regards,

Edson