0

javafx 演示示例中包含的 DataApp带有一个 ant 脚本,用于使用 MySQL 创建和填充数据库。配置 MySql 连接器后,只需调用一个 ant 任务即可:

<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>

但是,当我运行它时出现此异常:

  [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 专家,所以我不知道如何解决这个问题。任何帮助,将不胜感激。

4

1 回答 1

0

“用户”表的列数似乎从一个版本的 MySQL 更改为下一个版本。我可以通过登录 MySQL 控制台找到正确的数字,然后执行以下操作:

SELECT count(*) FROM information_schema.`COLUMNS` WHERE table_name = 'user' AND TABLE_SCHEMA = 'mysql';

然后我用:

SELECT * FROM user;

查看我自己的用户的值在哪里并复制这些值,正确的命令是:

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');
于 2013-08-09T01:40:38.637 回答