Click here to Skip to main content
16,016,306 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I make a simple project on Cafe Management(JAVA) in netbeans
But when I click save button, I got error!

"java.sql.SQLException: Column count doesn't match value count at row 1"

What I have tried:

mysql> show tables;
+------------------+
| Tables_in_newcms |
+------------------+
| user |
+------------------+
1 row in set (0.01 sec)

mysql> desc user;
+------------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------------+--------------+------+-----+---------+----------------+
| id | int | NO | PRI | NULL | auto_increment |
| name | varchar(200) | YES | | NULL | |
| email | varchar(200) | YES | UNI | NULL | |
| mobileNumber | varchar(11) | YES | | NULL | |
| address | varchar(200) | YES | | NULL | |
| password | varchar(200) | YES | | NULL | |
| securityQuestion | varchar(200) | YES | | NULL | |
| answer | varchar(200) | YES | | NULL | |
| status | varchar(20) | YES | | NULL | |
+------------------+--------------+------+-----+---------+----------------+
9 rows in set (0.01 sec)

I also add project folder, Here is link:
testCafeManagement – Google Drive[^]
Posted
Updated 11-Nov-22 21:40pm

1 solution

Without the relevant code - and I'm not going to wade through your entire project trying to guess which line might be giving you an error - we can't be specific.

But this is generally an SQL INSERT problem: you are trying to INSERT more data than there are columns in your table.
Each INSERT creates a row:
SQL
INSERT INTO MyTable (Column1, Column2) VALUES 1, 2
Says "I want to insert the value 1 into Column1, and the value 2 into Column2 of MyTable" and provided Column1 and Column2 exist in MyTable wit will work.
If you say this:
SQL
INSERT INTO MyTable (Column1, Column2) VALUES 1, 2, 3
Then the system has no idea where the value 3 is meant to go, and give you the error
Error
java.sql.SQLException: Column count doesn't match value count at row 1
So look at your error message and it'll tell you the line in your code that gave the problem (and most editors support CTRL+G to go directly to a line number). Look at that line and find the associated SQL command and check how many values you are trying to INSERT, and to where, then check the DB itself against that.

We can't do any of that for you!

You should expect to get errors every day, probably many times a day while you are coding - we all do regardless of how much experience we have! Sometimes, we misspell a variable, or a keyword; sometimes we forget to close a string or a code block. Sometimes the cat walks over your keyboard and types something really weird. Sometimes we just forget how many parameters a method call needs.

We all make mistakes.

And because we all do it, we all have to fix syntax errors - and it's a lot quicker to learn how and fix them yourself than to wait for someone else to fix them for you! So invest a little time in learning how to read error messages, and how to interpret your code as written in the light of what the compiler is telling you is wrong - it really is trying to be helpful!

So read this: How to Write Code to Solve a Problem, A Beginner's Guide Part 2: Syntax Errors[^] - it is talking about syntax errors but generally speaking the same information is given in the same format for runtime errors.
 
Share this answer
 
Comments
Sk. Azraf Sami 12-Nov-22 4:15am    
Thanks
OriginalGriff 12-Nov-22 4:44am    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900