# How to find what the sql excepion was with mysql

**URL:** <https://www.ruby-forum.com/t/how-to-find-what-the-sql-excepion-was-with-mysql/118541>\
**Category:** Ruby\
**Created:** [October 28, 2007, 3:15pm UTC](https://www.ruby-forum.com/t/how-to-find-what-the-sql-excepion-was-with-mysql/118541 "2007-10-28T15:15:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Junkone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e274bd/32.png) [@Junkone](https://www.ruby-forum.com/u/Junkone)\
**Post date:** [October 28, 2007, 3:15pm UTC](https://www.ruby-forum.com/t/how-to-find-what-the-sql-excepion-was-with-mysql/118541/1 "2007-10-28T15:15:59Z")

</div>

I got an exception  
E:/TradingTools/CODE/ImportTrade.rb:20:in `execute’

The associated piece of code is  
st= dbConn.prepare("insert into raw\_data

(SYMBOL,ACTION,SIZE,PRICE,DATE\_TIME\_OF\_TRADE ,EXECUTION,ACCOUNT\_ID)  
VALUES(?,?,?,?,?,?,?)")  
st.execute(dataArray[0],dataArray[1],dataArray[2],dataArray[3],tradeDate,dataArray[5],dataArray[6])  
st.close

How do i find out what the exception details were that was triggered  
at st.execute in this case.  
any assistance will be appreciated

---

<div class="post-metadata">

**Author:** ![Junkone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e274bd/32.png) [@Junkone](https://www.ruby-forum.com/u/Junkone)\
**Post date:** [October 28, 2007, 5:24pm UTC](https://www.ruby-forum.com/t/how-to-find-what-the-sql-excepion-was-with-mysql/118541/2 "2007-10-28T17:24:09Z")

</div>

Assuming the exception object is e, you can check out e.

Exceptions and rescuing them works like this (assuming you want to  
st.execute throws a MysqlException):

begin  
st.execute(dataArray[0],dataArray[1],dataArray[2],dataArray[3],tradeDate,dataArray[5],dataArray[6])  
rescue MysqlException =\> e  
puts e.message  
end

-Tom

---

<div class="post-metadata">

**Author:** ![Junkone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e274bd/32.png) [@Junkone](https://www.ruby-forum.com/u/Junkone)\
**Post date:** [October 28, 2007, 7:10pm UTC](https://www.ruby-forum.com/t/how-to-find-what-the-sql-excepion-was-with-mysql/118541/3 "2007-10-28T19:10:44Z")

</div>

On Oct 28, 12:21 pm, “Tom M.hinski” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > st= dbConn.prepare("insert into raw\_data
> 
> - Show quoted text  
> Great. It works. Can i get it to print the sql that was executed that  
> caused the error. becaues i am using a prepared statement
