# Print SQL Error

**URL:** <https://forum.inductiveautomation.com/t/print-sql-error/3969>\
**Category:** Ignition\
**Created:** [February 8, 2012, 7:54pm UTC](https://forum.inductiveautomation.com/t/print-sql-error/3969 "2012-02-08T19:54:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jonathan](https://avatars.discourse-cdn.com/v4/letter/j/aeb1de/32.png) [@Jonathan](https://forum.inductiveautomation.com/u/Jonathan)\
**Post date:** [February 8, 2012, 7:54pm UTC](https://forum.inductiveautomation.com/t/print-sql-error/3969/1 "2012-02-08T19:54:58Z")

</div>

I would like to show the SQL error to the user in a text box instead of a error box popping up, but I cannot seem to find where to find the string with the specific error information.

```auto
import sys
try:
	system.db.runPrepQuery("SQL Query with an error",[])
except:
	print sys.exc_info()[0]
	print sys.exc_info()[1]
	print sys.exc_info()[2]
```

the sys variables I am printing out above do not show the error message coming back from the database.

Thank you,

---

<div class="post-metadata">

**Author:** ![Greg.Buehler](https://avatars.discourse-cdn.com/v4/letter/g/ecc23a/32.png) [@Greg.Buehler](https://forum.inductiveautomation.com/u/Greg.Buehler)\
**Post date:** [February 8, 2012, 8:21pm UTC](https://forum.inductiveautomation.com/t/print-sql-error/3969/2 "2012-02-08T20:21:01Z")

</div>

You need to capture the actual exception Java threw.

```auto
import sys, java, java.lang

try:
	system.db.runPrepQuery("SQL Query with an error",[])
except java.lang.Exception, javaerror:
	print javaerror.getCause()
```

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [February 8, 2012, 8:26pm UTC](https://forum.inductiveautomation.com/t/print-sql-error/3969/3 "2012-02-08T20:26:20Z")

</div>

If you outputting to a text area you need to coerce everything to string:

`import sys
try:
   system.db.runPrepQuery("SQL Query with an error",[])
except:
   event.source.parent.getComponent('Text Area').text= str(sys.exc_info()[0])+"\n"+str(sys.exc_info()[1])+"\n"+str(sys.exc_info()[2])
`

print, whilst running in a project, outputs to the console, not to a component.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [February 8, 2012, 8:29pm UTC](https://forum.inductiveautomation.com/t/print-sql-error/3969/4 "2012-02-08T20:29:49Z")

</div>

Or, if you wanted it in an errorBox:

[code]import sys  
try:  
system.db.runPrepQuery(“SQL Query with an error”,[])  
except:  
system.gui.errorBox(str(sys.exc\_info()[0])+"\n"+str(sys.exc\_info()[1])+"\n"+str(sys.exc\_info()[2]))

[/code]
