java.sql.SQLException:列计数与第1行的值计数不匹配 [英] java.sql.SQLException: Column count doesn't match value count at row 1
本文介绍了java.sql.SQLException:列计数与第1行的值计数不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我桌子的结构:
id int AUTO_INCREMENT PRIMARY KEY
title text
url text
age int
以下是我尝试将数据保存到此表中的方法:
Here's how I am trying to save data into this table:
PreparedStatement ps=con.prepareStatement("insert into table(title, url, age) values ('\"+title+\",\"+url+\",\"+age+\"')");
System.out.println("Connected database successfully..");
ps.executeUpdate();
但是当我运行应用程序时,我得到了
But when I run the app, I get
java.sql.SQLException:列数与第1行的值计数不匹配
java.sql.SQLException: Column count doesn't match value count at row 1
我想问题可能出在 id 列中,如何解决?
I guess the problem might be in the id column, how to solve it?
推荐答案
实际上,你有一个不同的问题(你只传递一个值) -
Actually, you have a different problem (you're only passing one "value") -
PreparedStatement ps=con.prepareStatement("insert into table(title, url, age) "
+ "values (?,?,?)");
ps.setString(1, title);
ps.setString(2, url);
ps.setInt(3, age); // <-- at a guess!
原始查询将所有三个值都放在一个字符串中'\+ title + \,\+ url + \,\+ age + \'
。
You original query put all three values in one string '\"+title+\",\"+url+\",\"+age+\"'
.
这篇关于java.sql.SQLException:列计数与第1行的值计数不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文