![]() |
| Register | |||||||
| General Software This is the forum for general discussions about software. |
![]() |
| | LinkBack | Thread Tools |
| | #1 (permalink) | ||
| I'm a regular Join Date: 12 Aug 2005
Posts: 269
Reputation: 122 ![]() ![]() Rep Power: 5 | I came across this error when trying to use the "NOT EXISTS" statement in my SQL query. Crap, I have double checked with the codes I found on the internet but still to no avail this is the error generated by Eclipse, FYI I'm implementing MySQL inside my Java program: Quote:
Quote:
__________________ -if love is like butterfly, then unwanted love is like a bunch of flies- | ||
| | |
| SPONSOR |
| |
| | #2 (permalink) | |
| I'm a regular Join Date: 12 Aug 2005
Posts: 269
Reputation: 122 ![]() ![]() Rep Power: 5 | Used a different approach to avoid the NO EXISTS sql error. I'm trying to insert values into a table where the insertion will include a Primary Key value. Therefore the program needs to check whether the PK value has existed inside the table or not, else it will cause an Duplicate value error. These are the codes I used: Quote:
__________________ -if love is like butterfly, then unwanted love is like a bunch of flies- | |
| | |
| | #3 (permalink) |
| I'm a regular Join Date: 15 Jan 2004 Location: Somewhere out there
Posts: 350
Reputation: 15 ![]() Rep Power: 5 | u can try to just insert into the table without checking anyways. U'll get an SQLException raised when there's a PK conflict. when you get an exception, here's how you handle it: SQLException has a method that allows u to get the exception code for the exception raised. this is vendor specific, so you will nee dto check the mysql documentation on the error codes for their JDBC driver. if it the error code returned matches the error code for PK conflict, then you know that the error is caused by that, so you can handle it accordingly. alternatively, you can use hibernate (www.hibernate.org) do handle ya database handling work without you needing to do a single line of SQL |
| | |
| | #4 (permalink) |
| I'm a regular Join Date: 12 Aug 2005
Posts: 269
Reputation: 122 ![]() ![]() Rep Power: 5 | I did enter all the codes above into try catch block, if I don't Eclipse will generate a compile error anyway Is hibernate a freeware? I'm doing it for my company so I can't use products without license
__________________ -if love is like butterfly, then unwanted love is like a bunch of flies- |
| | |
| | #5 (permalink) | |
| I'm a regular Join Date: 15 Jan 2004 Location: Somewhere out there
Posts: 350
Reputation: 15 ![]() Rep Power: 5 | Quote:
actually, that's the beauty of try/catch blocks. in the try, do place the code that might fail (such as the insertion that may have the PK violation), then you clean up any messes caused by errors inside the catch block, and in the finally block, that's where it all comes to an end, such as commiting the series of sql statements that's been done and so on. yup, hibernate is free | |
| | |