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