2016-10-14 2 views
-1

Я использую Scriptella для копирования данных из одной таблицы в другую таблицу (другую базу данных) на Mysql. Для источника я использовал таблицу film из базы данных образцов Mysql Sakila.Ошибка копирования данных Scriptella в mysql

При копировании данных я получаю это сообщение об ошибке.

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 Code

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. 

кажется, что конкретная БД строка содержит значение 2006 в столбце, где ожидается тип TIMESTAMP, формат которого для MySQL, кажется,

TIMESTAMP - format: YYYY-MM-DD HH:MI:SS 
+0

Спасибо за ваш ответ. Но почему он конвертирует 2006 в timestamp, поскольку столбец 'release_year' имеет тип' year'. –

+0

@g_p: У меня нет MySQL, поэтому я не могу воспроизвести его для вас. Я бы предложил поставить точки останова в соответствующих частях вашей stacktrace и попытаться отладить, почему это преобразование типа пытается. scriptella.core.QueryExecutor $ QueryCtxDecorator.processRow (QueryExecutor.java:114) кажется хорошей отправной точкой – hammerfest

Смежные вопросы