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
• 12,240 points
43 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
• 20,880 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
• 12,240 points
252 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
• 12,240 points
64 views
0 votes
0 answers

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

When I'm try to drop the table ...READ MORE

Sep 8 in Database by Kithuzzz
• 12,240 points
26 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,056 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
2,638 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
• 12,240 points
98 views
0 votes
0 answers
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
• 20,880 points
60 views
0 votes
1 answer
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