java sql SQLException Column count doesn t match value count at row 1

0 votes

I'm trying to change values via JDBC, but I keep getting the same problem for various tables and schemas.

Consider that I have a table similar to this.

+----------------+-------------+------+-----+---------+-------+
| Field          | Type        | Null | Key | Default | Extra |
+----------------+-------------+------+-----+---------+-------+
| field1         | varchar(50) | YES  |     | NULL    |       |
| field2         | varchar(50) | YES  |     | NULL    |       |
+----------------+-------------+------+-----+---------+-------+

Then I tried  to add a row:

String Text1 = text1;
String Text2 = text2;
String Query_String = "INSERT INTO tablename(field1,field2) VALUES ('"+Text1+","+Text2+"')";
Query_Statement.executeUpdate(Query_String);

Although there are the same amount of columns and no further commas in the text, I still receive the message "java.sql.SQLException: Column count doesn't match value count at row 1."

Since I was able to make it work with a single column, I'm confident that it's a simple syntactic error.

Can someone please help me with this?

Sep 19, 2022 in Database by Kithuzzz
• 38,020 points
2,107 views

1 answer to this question.

0 votes

I think PreparedStatement would be a better choice. I hope this helps you. 

answered Sep 20, 2022 by narikkadan
• 63,680 points

Related Questions In Database

0 votes
0 answers

java.sql.SQLException: Missing IN or OUT parameter at index:: 1

Using OJDBC 6, I created some Java ...READ MORE

Aug 15, 2022 in Database by Kithuzzz
• 38,020 points
6,537 views
0 votes
0 answers
0 votes
0 answers

The java.sql.SQLException: Fail to convert to internal representation

I want to do this query: String query ...READ MORE

Aug 20, 2022 in Database by Kithuzzz
• 38,020 points
2,061 views
0 votes
1 answer

Add a column with a default value to an existing table in SQL Server

Syntax: ALTER TABLE {TABLENAME} ADD {COLUMNNAME} {TYPE} {NULL|NOT ...READ MORE

answered Sep 12, 2022 in Database by narikkadan
• 63,680 points
2,441 views
0 votes
1 answer

Accessing connection from different class in Java / MySQL?

You should just instantiate DoComms with every ...READ MORE

answered Nov 14, 2018 in Database by nirvana
• 3,130 points
1,910 views
0 votes
0 answers

java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)

This is the exception on getConnection(): java.sql.SQLException: Access denied ...READ MORE

May 16, 2022 in Java by Kichu
• 19,050 points
7,009 views
0 votes
0 answers

java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/dbname [duplicate]

I have this Java program: MySQLConnectExample.java import java.sql.*; import java.util.Properties; public ...READ MORE

Aug 21, 2022 in Database by Kithuzzz
• 38,020 points
2,156 views
0 votes
0 answers
0 votes
1 answer

How to solve : SQL Error: ORA-00604: error occurred at recursive SQL level 1

I saw the problem in the line ...READ MORE

answered Sep 10, 2022 in Database by narikkadan
• 63,680 points
4,810 views
0 votes
1 answer

java.sql.SQLException: - ORA-01000: maximum open cursors exceeded

The maximum-open-cursors error, also known as ORA-01000, ...READ MORE

answered Sep 11, 2022 in Database by narikkadan
• 63,680 points

edited Jul 5, 2023 by Khan Sarfaraz 3,569 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP