Bonsoir
Je souhaite utiliser ANT1.7.1 et DBUNIT 2.4.8 pour charger des données dans ma Base Mysql
Le script se deroule en successfull, mais rien n'est inséré.
J'ai testé une insertion JDBC avec le meme driver sur la meme base qui fonctionne.
Mon script ant
Mon log
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 - <project name="project1" default="import" basedir=".."> - <taskdef name="dbunit" classname="org.dbunit.ant.DbUnitTask"> - <classpath> <path location="./lib/mysql-connector-java-5.1.14-bin.jar" /> <path location="./lib/antlr-2.7.6.jar" /> <path location="./lib/dbunit-2.4.8.jar" /> <path location="./lib/commons-collections-3.1.jar" /> - <!-- <path location="./lib/commons-logging-1.1.1.jar"/> --> <path location="./lib/dom4j-1.6.1.jar" /> <path location="./lib/log4j-1.2.16.jar" /> <path location="./lib/slf4j-api-1.5.6.jar" /> <path location="./lib/slf4j-log4j12-1.5.2.jar" /> </classpath> </taskdef> <typedef resource="org/dbunit/ant/antlib.xml" /> - <target name="import" description="Recreates global tables in MYSQL from XML files" depends=""> - <dbunit driver="com.mysql.jdbc.Driver" url="jdbc:mysql://192.168.17.4:3306/employes" userid="gestion" password="gestion"> <operation type="INSERT" src="/prj_java/TestAgarder/hibernate4/data/init_data.xml" format="xml" /> </dbunit> <echo message="apres" /> </target> </project>
Mon fichier XML init_data.xml
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 Build sequence for target(s) `import' is [import] Complete build sequence is [import, ] import: [dbunit] log4j:WARN No appenders could be found for logger (org.dbunit.ant.Op eration). [dbunit] log4j:WARN Please initialize the log4j system properly. [dbunit] log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info. [dbunit] Loading com.mysql.jdbc.Driver using system loader. [dbunit] connecting to jdbc:mysql://192.168.17.4:3306/employes [dbunit] Created connection for schema 'null' with config: org.dbunit.databas e.DatabaseConfig[, _propertyMap={http://www.dbunit.org/properties/statementFacto ry=org.dbunit.database.statement.PreparedStatementFactory@66e815, http://www.dbu nit.org/features/caseSensitiveTableNames=false, http://www.dbunit.org/properties /fetchSize=100, http://www.dbunit.org/features/batchedStatements=false, http://w ww.dbunit.org/properties/metadataHandler=org.dbunit.database.DefaultMetadataHand ler@ece65, http://www.dbunit.org/properties/datatypeFactory=org.dbunit.dataset.d atatype.DefaultDataTypeFactory[_toleratedDeltaMap=org.dbunit.dataset.datatype.To leratedDeltaMap@106082], http://www.dbunit.org/properties/escapePattern=null, ht tp://www.dbunit.org/properties/batchSize=100, http://www.dbunit.org/features/qua lifiedTableNames=false, http://www.dbunit.org/properties/tableType=[Ljava.lang.S tring;@1301ed8, http://www.dbunit.org/properties/resultSetTableFactory=org.dbuni t.database.ForwardOnlyResultSetTableFactory@3901c6, http://www.dbunit.org/featur es/datatypeWarning=true}] [dbunit] Executing operation: INSERT [dbunit] on file: C:\prj_java\TestAgarder\hibernate4\data\init_da ta.xml [dbunit] with format: xml [echo] apres BUILD SUCCESSFUL Total time: 0 seconds
Une insertion par JDBC fonctionne bien ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6 <?xml version="1.0" encoding="UTF-8"?> <dataset> <TEST1 TEST_ID="6" NOM="TESTC" COUNT="6"/> </dataset>
Ou est mon erreur dans la compréhension de DBUNIT ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37 public static void main(String[] args) { try { String url = "jdbc:mysql://192.168.17.4:3306/employes"; String user = "gestion"; String password = "gestion"; Class.forName("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection(url, user, password); con.setAutoCommit(false); // create prepared statement try { String sql = "INSERT INTO test1 (TEST_ID,NOM,COUNT) VALUES(?,?,?)"; PreparedStatement statement = con.prepareStatement(sql); // en sp�cifiant bien les types SQL cibles printd("avant premier insert"); statement.setObject(1, new Integer(5), Types.INTEGER); statement.setObject(2, "nom", Types.VARCHAR); statement.setObject(3, new Integer(5), Types.INTEGER); statement.executeUpdate(); statement.close(); con.commit(); con.close(); } catch (SQLException e) { printd(e.getMessage()); } } catch (Exception e1) { printd("Erreur Message=" + e1.getMessage()); e1.printStackTrace(); } }
Le tutorial d'ou je suis parti
http://dbunit.sourceforge.net/anttask.html
Partager