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 in Database by Kithuzzz
• 20,660 points
248 views

1 answer to this question.

0 votes

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

answered Sep 20 by narikkadan
• 37,660 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 in Database by Kithuzzz
• 20,660 points
1,006 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 in Database by Kithuzzz
• 20,660 points
270 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 in Database by narikkadan
• 37,660 points
209 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,134 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 in Java by Kichu
• 19,040 points
3,676 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 in Database by Kithuzzz
• 20,660 points
564 views
0 votes
0 answers
0 votes
1 answer
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 in Database by narikkadan
• 37,660 points
158 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