javafx DataApp演示中的数据库出错 [英] Error with database in javafx DataApp demo
问题描述
javafx演示示例附带一个ant脚本,用MySQL创建和填充数据库。配置MySql连接器后,只需调用ant任务:
The DataApp included in the javafx demos example comes with an ant script to create and populate a database with MySQL. After configuring the MySql connector it is only a matter of calling an ant task:
<target name="-post-init" >
<input message="Please enter Mysql password for root@localhost:" addproperty="mysql.password"/>
<!-- first create user and database -->
<echo>Creating "dataapp" user and "APP" database...</echo>
<sql driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:4447/mysql"
userid="root"
password="mysql-connector-java-5.1.18.jar"
classpath="${libs.MySQLDriver.classpath}"
>
DELETE FROM user WHERE User = 'dataapp';
DELETE FROM db WHERE User = 'dataapp';
INSERT INTO user VALUES ('localhost','dataapp','*B974A83D18BB105D0C9186756F485406E6E6039B','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0,'',NULL);
INSERT INTO db VALUES ('localhost','APP','dataapp','Y','Y','Y','Y','Y','Y','N','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','N','Y');
DROP DATABASE IF EXISTS APP;
CREATE DATABASE APP;
FLUSH PRIVILEGES;
</sql>
<echo>Creating tables and views...</echo>
<sql driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/APP"
userid="dataapp"
password="dataapp"
classpath="${libs.MySQLDriver.classpath}"
src="${basedir}/create-database.sql"/>
<echo>Populating zip code table(this might take a little while)...</echo>
<sql driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/APP"
userid="dataapp"
password="dataapp"
classpath="mysql-connector-java-5.1.18.jar"
src="${basedir}/zip_code_inserts.sql"/>
</target>
然而,我在运行时收到此异常:
However, I am getting this exception when I run it:
[sql] Failed to execute: INSERT INTO user VALUES ('localhost','dataapp','*B974A83D18BB105D0C9186756F485406E6E6039B','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0,'',NULL)
出现此异常:
java.sql.SQLException: Column count doesn't match value count at row 1
我认为字段的数量不是应该的,但是我我不是MySQL专家,所以我不知道如何解决这个问题。任何帮助将不胜感激。
I think that the number of fields is not what it should be, but I am no MySQL expert, so I don't know how to fix this. Any help would be appreciated.
推荐答案
用户表的列数似乎从一个版本的MySQL更改到下一个。我可以通过登录MySQL控制台找到正确的数字,并执行:
The number of columns that the 'user' table has seems to change from one version of MySQL to the next one. I was able to find the correct number by logging into the MySQL console, and do:
SELECT count(*) FROM information_schema.`COLUMNS` WHERE table_name = 'user' AND TABLE_SCHEMA = 'mysql';
然后我用过:
SELECT * FROM user;
查看我自己用户的值在哪里并复制那些,正确的命令:
to see what where the values for my own user and copy those, the correct command for:
Server version: 5.1.61-community-log
是:
INSERT INTO user VALUES ('localhost','dataapp','*B974A83D18BB105D0C9186756F485406E6E6039B','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','','0','0','0','0');
这篇关于javafx DataApp演示中的数据库出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!