Tony Docherty wrote:Welcome to the ranch.
Please use code tags when posting code and is this the best forum for a DB question? I'll ask the mods to move it for you.
....
OCUP UML fundamental and ITIL foundation
The quieter you are, the more you are able to hear.
Kemal Sokolovic wrote:Why are you indexing parameters of you statement as 2-14 when it should be 1-13? You have 13 parameters to set, and as you could see in the API indexing starts at value 1. That should throw an exception.
charles macharia wrote:no the program is running fine but it catches an error when i attempt to insert data into the db
and i have started from 2 because im not sure if the primary key is also included
The quieter you are, the more you are able to hear.
Kemal Sokolovic wrote:
charles macharia wrote:no the program is running fine but it catches an error when i attempt to insert data into the db
and i have started from 2 because im not sure if the primary key is also included
Well, you certainly can't catch an exception unless you execute the code that produces it - in this case the code for inserting new data into your database.
I think you didn't get how the PreparedStatement works. When you set those parameters (1-13), indexes don't represent columns in the database but values that will be set instead of those question marks in your sql query you keep in sql String (I trivialized the explanation, but that's how you can think of it). No matter what the order of columns is in the database, you're setting parameters based on your sql query. You might as well write something like this (supposing other columns can contain null values):
That will insert a new row in your database table with values set above, and other columns having null values.
i seem to have done as you have told me but no change is observed
On the other hand, message like "Error on database operation,Updation failure" is not very suitable for this kind of situation. To you as developer it says nothing about where the problem occured, and to other users it's "too technical" so you need to take care of that too in your applications.
And one final note: Never, ever hide the exceptions in your applications. You better crash it, at least you'll know it's not working at all.
charles macharia wrote:i have done all you have advised me to do but no change is observed in the database
wendy gibbons please explain more