Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I write an SQL query that fails?

I need this query for testing exception handling, so I would prefer that the query is not schema dependent. I am looking for something like SELECT 1; but of course that doesn't fail.

I am using Java and MySQL but I hope to find answers that doesn't depend on programming languages and/or RDBMSs.

like image 833
muhuk Avatar asked Oct 15 '25 05:10

muhuk


2 Answers

What about "SELECT 1/0" for starters?

like image 129
Jim O'Neil Avatar answered Oct 16 '25 20:10

Jim O'Neil


You could put an invalid token into the query

select doesnotexist.* from something_else

Or of course, what you should do is mock out the method and have it throw the exception during your test.

like image 33
Jonathan Henson Avatar answered Oct 16 '25 20:10

Jonathan Henson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!