我正在使用Scriptella将数据从一个表复制到另一个表(不同的数据库)上。对于源代码,我使用了Mysql示例数据库Sakila中的表film。
复制数据时,我收到此错误消息。
Exception in thread "main" scriptella.execution.EtlExecutorException: Location: /etl/query[1]/script[1]
JDBC provider exception: Unable to get parameter 4
Error codes: [S1009, 0]
Driver exception: java.sql.SQLException: Cannot convert value '2006' from column 4 to TIMESTAMP.
at scriptella.execution.EtlExecutor.execute(EtlExecutor.java:190)
at com.zensar.scrptellaTest.App.main(App.java:21)
Caused by: scriptella.core.ExceptionInterceptor$ExecutionException: /etl/query[1]/script[1] failed: Unable to get parameter 4
at scriptella.core.ExceptionInterceptor.execute(ExceptionInterceptor.java:44)
at scriptella.core.QueryExecutor$QueryCtxDecorator.processRow(QueryExecutor.java:114)
at scriptella.jdbc.StatementWrapper.query(StatementWrapper.java:92)
at scriptella.jdbc.SqlExecutor.statementParsed(SqlExecutor.java:128)
at scriptella.jdbc.SqlParserBase.handleStatement(SqlParserBase.java:129)
at scriptella.jdbc.SqlParserBase.parse(SqlParserBase.java:72)
at scriptella.jdbc.SqlExecutor.execute(SqlExecutor.java:85)
at scriptella.jdbc.JdbcConnection.executeQuery(JdbcConnection.java:222)
at scriptella.core.QueryExecutor.execute(QueryExecutor.java:71)
at scriptella.core.ContentExecutor.execute(ContentExecutor.java:73)
at scriptella.core.ElementInterceptor.executeNext(ElementInterceptor.java:56)
at scriptella.core.StatisticInterceptor.execute(StatisticInterceptor.java:41)
at scriptella.core.ElementInterceptor.executeNext(ElementInterceptor.java:56)
at scriptella.core.ConnectionInterceptor.execute(ConnectionInterceptor.java:36)
at scriptella.core.ElementInterceptor.executeNext(ElementInterceptor.java:56)
at scriptella.core.ExceptionInterceptor.execute(ExceptionInterceptor.java:39)
at scriptella.core.Session.execute(Session.java:103)
at scriptella.execution.EtlExecutor.execute(EtlExecutor.java:227)
at scriptella.execution.EtlExecutor.execute(EtlExecutor.java:183)
... 1 more
这是表格中的一行。
'1', 'ACADEMY DINOSAUR', 'A Epic Drama of a Feminist And a Mad Scientist who must Battle a Teacher in The Canadian Rockies', 2006, '1', NULL, '6', '0.99', '86', '20.99', 'PG', 'Deleted Scenes,Behind the Scenes', '2006-02-15 05:03:42'
这两个表的DDL语句。
sakila.film
CREATE TABLE `film` (
`film_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
`title` varchar(255) NOT NULL,
`description` text,
`release_year` year(4) DEFAULT NULL,
`language_id` tinyint(3) unsigned NOT NULL,
`original_language_id` tinyint(3) unsigned DEFAULT NULL,
`rental_duration` tinyint(3) unsigned NOT NULL DEFAULT '3',
`rental_rate` decimal(4,2) NOT NULL DEFAULT '4.99',
`length` smallint(5) unsigned DEFAULT NULL,
`replacement_cost` decimal(5,2) NOT NULL DEFAULT '19.99',
`rating` enum('G','PG','PG-13','R','NC-17') DEFAULT 'G',
`special_features` set('Trailers','Commentaries','Deleted Scenes','Behind the Scenes') DEFAULT NULL,
`last_update` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`film_id`),
KEY `idx_title` (`title`),
KEY `idx_fk_language_id` (`language_id`),
KEY `idx_fk_original_language_id` (`original_language_id`),
CONSTRAINT `fk_film_language` FOREIGN KEY (`language_id`) REFERENCES `language` (`language_id`) ON UPDATE CASCADE,
CONSTRAINT `fk_film_language_original` FOREIGN KEY (`original_language_id`) REFERENCES `language` (`language_id`) ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=1001 DEFAULT CHARSET=utf8;
trg.film
CREATE TABLE `film` (
`film_id` smallint(5) unsigned NOT NULL,
`title` varchar(255) NOT NULL,
`description` text,
`release_year` year(4) DEFAULT NULL,
`language_id` tinyint(3) unsigned NOT NULL,
`original_language_id` tinyint(3) unsigned DEFAULT NULL,
`rental_duration` tinyint(3) unsigned NOT NULL DEFAULT '3',
`rental_rate` decimal(4,2) NOT NULL DEFAULT '4.99',
`length` smallint(5) unsigned DEFAULT NULL,
`replacement_cost` decimal(5,2) NOT NULL DEFAULT '19.99',
`rating` enum('G','PG','PG-13','R','NC-17') DEFAULT 'G',
`special_features` set('Trailers','Commentaries','Deleted Scenes','Behind the Scenes') DEFAULT NULL,
`last_update` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Scriptella etl.xml
<!DOCTYPE etl SYSTEM "http://scriptella.javaforge.com/dtd/etl.dtd">
<etl>
<description>Scriptella ETL File Template.</description>
<!-- Connection declarations -->
<connection id="source" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://127.0.0.1:3306/sakila" user="root" password="12345" />
<connection id="target" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://127.0.0.1:3306/trg" user="root" password="12345" />
<!-- Uncomment and modify to run a query-based transformation -->
<query connection-id="source">
SELECT * FROM film;
<script connection-id="target">
INSERT INTO film VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12, ?13);
</script>
</query>
</etl>
Java代码
public static void main(String[] args) throws EtlExecutorException {
ProgressIndicatorBase indicatorBase = new ProgressIndicatorBase() {
@Override
protected void show(String label, double progress) {
System.out.println(label + "--> " + progress);
}
};
EtlExecutor.newExecutor(new File("etl.xml")).execute(indicatorBase);
}
请告诉我我在哪里做错了,或者有解决方法。
答案 0 :(得分:0)
您收到的例外是
Driver exception: java.sql.SQLException: Cannot convert value '2006' from column 4 to TIMESTAMP.
似乎特定的DB行在期望TIMESTAMP类型的列中包含值2006,MySQL的格式似乎是
TIMESTAMP - format: YYYY-MM-DD HH:MI:SS
答案 1 :(得分:0)
好吧,我想我知道了。 只需在参数周围加上引号
?4 应该看起来像“?4”
在源代码中,日期被转换为字符串。 因此,当使用不带引号的字符串日期创建插入时,日期解析会在一年后停止,只剩下一个数字