Skip to content

Commit 6062589

Browse files
committed
SVY-9426 sql exception not logged correctly
1 parent b5452eb commit 6062589

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

servoy_shared/src/com/servoy/j2db/dataprocessing/DataException.java

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public DataException()
4343
public DataException(int errorCode, SQLException ex, String sql)
4444
{
4545
super(errorCode);
46-
msg = ex.getMessage();
46+
msg = getChainedMessage(ex);
4747
sqlState = ex.getSQLState();
4848
vendorErrorCode = ex.getErrorCode();
4949
this.sql = sql;
@@ -60,10 +60,25 @@ public DataException(int errorCode, Object value, Exception cause)
6060
initCause(cause);
6161
}
6262

63+
private static String getChainedMessage(SQLException ex)
64+
{
65+
SQLException e = ex.getNextException();
66+
StringBuilder sb = new StringBuilder(ex.getMessage());
67+
while (e != null)
68+
{
69+
sb.append("\nNextException: SQL Error: ").append(e.getErrorCode()) //
70+
.append(", SQLState: ").append(e.getSQLState()) //
71+
.append(", Message: ").append(e.getMessage());
72+
e = e.getNextException();
73+
}
74+
return sb.toString();
75+
}
76+
77+
6378
// THIS METHOD IS REMOVED FROM InstanceJavaMethod WITH A HACK to keep compatibility with old ways :) - when ServoyException was not using js_...
6479
/**
6580
* @sameas com.servoy.j2db.util.ServoyException#js_isServoyException()
66-
*
81+
*
6782
* @deprecated Use "typeof" operator instead.
6883
*/
6984
@Deprecated
@@ -77,7 +92,7 @@ public boolean js_isServoyException()
7792
* This method will always return true; it makes the distinction between DataException and ServoyException.
7893
*
7994
* @deprecated Use "typeof" operator instead.
80-
*
95+
*
8196
* @sample
8297
* var record = array[i];
8398
* application.output(record.exception);
@@ -88,7 +103,7 @@ public boolean js_isServoyException()
88103
* application.output("VendorErrorCode: " + record.exception.getVendorErrorCode());
89104
* }
90105
* @return true.
91-
106+
92107
*/
93108
@Deprecated
94109
public boolean js_isDataException()
@@ -191,16 +206,16 @@ public int js_getVendorErrorCode()
191206

192207
/**
193208
* Returns the parameters of the SQL query that caused this DataException in an array.
194-
*
209+
*
195210
* @sample
196211
* var record = array[i];
197212
* application.output(record.exception);
198213
* if (record.exception instanceof DataException)
199-
* {
214+
* {
200215
* var param = record.exception.getParameters();
201216
* for (j = 0; j < param.length; j++)
202-
* {
203-
* application.output("SQL Parameter [" + j + "]: " + param[j]);
217+
* {
218+
* application.output("SQL Parameter [" + j + "]: " + param[j]);
204219
* }
205220
* }
206221
* @return the parameters of the SQL query that caused this DataException in an array.

0 commit comments

Comments
 (0)