aspose file tools*
The moose likes JDBC and the fly likes cannot write a new customer to the database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "cannot write a new customer to the database" Watch "cannot write a new customer to the database" New topic
Author

cannot write a new customer to the database

Ana Pan
Greenhorn

Joined: Oct 23, 2012
Posts: 4

Hello,

I have a problem with my code and hope that somebody can point me what am I doing wrong.
My program uses MVC structure. Part of it is the customer login (working), add(not working) and update(not working).

Right now, I am trying to get my addCustomer part working. When I deploy it, it gives me

java.sql.SQLException: Parameter index out of range (9 > number of parameters, which is 8)

I cannot find where I did that mistake, please help me find it.

addCustomer.html


CustomerSystem.java (controller)


Customer.java (customer class)


Thank you very much in advance for any help or advice,
Ana
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18662
    
    8

Here's the relevant code from your post:



Your INSERT statement has 8 parameters (those question marks). They are numbered from 1 to 8. So your numbering in the setString calls is off by 1.
Ana Pan
Greenhorn

Joined: Oct 23, 2012
Posts: 4

Ok,
I have edited that piece of the code.
Now it looks like this:



Unfortunately, now I get

SEVERE: The log message is null.
com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Column 'userName' cannot be null


for some reason it doesn't take userName info...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: cannot write a new customer to the database