This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I am getting SQLException with Error Message of this Exception is "No such column name" and Error Code is -79738. I am connected to Informix DB. My requirement is that I want to print column name too in the error message.
Here is my code snippet
exception is thrown at first statement because actual column is input_record not input_recordss and Error Message is "No such column name". I want following Error Message
"column input_recordss not found".
you can catch the SQLExecption and throw new SQLException with your message.
Joined: Oct 25, 2012
Actually I do not want to print my message by throwing new SQL Exception because for this I have to store all the column names in Variables. These variables will then be used in Error Message. If i donot store them in variable then I donot have access to column name. Is there anyother way?
well I am unable to find a way to get the 'wrong column name' through exception. lets see what others have to say about this.
as of now what I can think of is that you can use column index rather than column name to avoid this thing.
if you have to do this, then there is a long way, get the column name using meta data and then compare them.(I dont think its a good way to go about it though)
Where are the column names coming from you are using to get the results? as in the example you have provided you have them hard coded, so throwing a new exception would be easy simply hard code it again.
if the column names are coming from variables you can simply use the variable to build your new exception
throw new SqlException("column "+variable+" not found").
if this is not enough help we will need to see your code as we are just guessing at what you can do.