# Getting better exception description from SQL java.lang.Exception?

**URL:** <https://forum.inductiveautomation.com/t/getting-better-exception-description-from-sql-java-lang-exception/76628>\
**Category:** Ignition\
**Created:** [July 20, 2023, 7:26am UTC](https://forum.inductiveautomation.com/t/getting-better-exception-description-from-sql-java-lang-exception/76628 "2023-07-20T07:26:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [July 20, 2023, 7:26am UTC](https://forum.inductiveautomation.com/t/getting-better-exception-description-from-sql-java-lang-exception/76628/1 "2023-07-20T07:26:19Z")

</div>

Is there any way to get useful information from a SQL exception, other than just "your query didn't work :/"?

This is what I am getting at the moment, and while I've worked out that I removed one of the fields but forgot to remove a `?` as well, it took me a little while to find it. It would have been nice to see some more descriptive error, but is this possible?

```auto
Traceback (most recent call last): File "<module:project.gui>", line 47, in add_part_calib Exception: java.lang.Exception: Error executing system.db.runPrepUpdate(INSERT INTO dat_calibration_log (measured_length, expected_length, machine_id, t_stamp) VALUES (?,?,?,?,?), [124, 123, 1, Thu Jul 20 16:52:01 ACST 2023], SQLServer, , false, false)

```

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [July 20, 2023, 11:41am UTC](https://forum.inductiveautomation.com/t/getting-better-exception-description-from-sql-java-lang-exception/76628/2 "2023-07-20T11:41:30Z")

</div>

In gateway scopes, you can follow the chain of causes back to the error that actually came from the JDBC driver. In Vision/Designer scope, the chain is partly there too, but the JDBC classes don't exist, so the gateway interface stringifies those.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [July 20, 2023, 12:12pm UTC](https://forum.inductiveautomation.com/t/getting-better-exception-description-from-sql-java-lang-exception/76628/3 "2023-07-20T12:12:15Z")

</div>

From a client/designer (I guess this may not work as well via the gateway per Phils point?) point of view if you catch the error in a `java.lang.Throwable` the `e.cause` tend to give you a good idea of what went wrong. Copying your example here's what I get if my columns and ? mismatch -

```auto
import java.lang.Throwable

try:
	system.db.runPrepQuery("INSERT INTO TestingTable (field1) VALUES (?,?)",['hi','bye'])
except java.lang.Throwable, e:
	print str(e)
	print str(e.cause)

```

prints

```auto
java.lang.Exception: Error executing system.db.runPrepQuery(INSERT INTO TestingTable (field1) VALUES (?,?), , [hi, bye], )
com.inductiveautomation.ignition.client.gateway_interface.GatewayException: (conn=91) Column count doesn't match value count at row 1

```

Now I see my column count doesn't match.

If you do it without a try/except, the last line is what you see -  
`java.lang.Exception: java.lang.Exception: Error executing system.db.runPrepQuery(INSERT INTO TestingTable (field1) VALUES (?,?), , [hi, bye], )` which isn't helpful but the `caused by:` lines above it do give more context as to what actually went wrong -

```auto
Caused by: java.lang.Exception: Error executing system.db.runPrepQuery(INSERT INTO TestingTable (field1) VALUES (?,?), , [hi, bye], )
Caused by: com.inductiveautomation.ignition.client.gateway_interface.GatewayException: (conn=91) Column count doesn't match value count at row 1
Caused by: java.sql.SQLException: (conn=91) Column count doesn't match value count at row 1

```

---

<div class="post-metadata">

**Author:** ![marten\_gorter](https://avatars.discourse-cdn.com/v4/letter/m/48db29/32.png) [@marten\_gorter](https://forum.inductiveautomation.com/u/marten_gorter)\
**Post date:** [April 19, 2024, 3:23pm UTC](https://forum.inductiveautomation.com/t/getting-better-exception-description-from-sql-java-lang-exception/76628/4 "2024-04-19T15:23:06Z")

</div>

Awesome! This is the solution that I was looking for.
