I was having difficulty making it work for MySQL. The issue turned out to be around line 250 where you're calling XPathHelper.getBoolean(), which returns true if the xpath matches any node, regardless of the node's value. I changed this to call XPathHelper.getString() and to compare the node's value to true.
Along the way I did a bit of refactoring so that statements for non-multiStatementDriver's are cleaned up incrementally rather than being pushed onto a stack. Here's the diff (from the version in cvs, not the released version) in case you're interested.
Index: src/main/java/net/sf/dbsql2xml/Dbsql2xml.java===================================================================
RCS file: /cvsroot/dbsql2xml/Dbsql2Xml/src/main/java/net/sf/dbsql2xml/Dbsql2xml.java,v
retrieving revision 1.3
diff -r1.3 Dbsql2xml.java
3c3
< * 2005�2006 Stepan Rybar This library is free software; you can redistribute it and/or modify it under the terms of the GNU
---
> * 2005�2006 Stepan Rybar This library is free software; you can redistribute it and/or modify it under the terms of the GNU
71,72c71
< private Statement statement = null;
< private PreparedStatement preparedStatement = null;
---
> private Statement globalStatement = null;
79,80d77
< private int cursorCount = 0;
< private Vector statements = new Vector();
251,257c248
< if (xPathHelper.getBoolean("config/connectionProperties/multiStatementDriver", document).booleanValue()) {
< multiStatementDriver = true;
< }
< else {
< multiStatementDriver = false;
< }
< statement = getStatement(connection);
---
> multiStatementDriver = xPathHelper.getString("config/connectionProperties/multiStatementDriver", document).equalsIgnoreCase("true");
262,269d252
< if (cursorCount++ > 9) {
< Iterator iter = statements.iterator();
< while (iter.hasNext()) {
< Statement s = (Statement) iter.next();
< s.close();
< }
< statement = null;
< }
528a512
>
529a514,515
> Statement statement = null;
> PreparedStatement preparedStatement = null;
533c519,520
< resultSet = getResultSet(connection, tableSql, paramVals);
---
> preparedStatement = getPreparedStatement(connection, tableSql);
> resultSet = getResultSet(preparedStatement, paramVals);
537c524,525
< resultSet = getResultSet(connection, tableSql);
---
> statement = getStatement(connection);
> resultSet = getResultSet(statement, tableSql);
560c548
< log.error(tableSql);
---
> log.error("tableSql=\"" + tableSql + "\", multiStatementDriver=\"" + multiStatementDriver + "\"");
566,567c554,566
< try {
< resultSet.close();
---
> if (resultSet != null) {
> try {
> resultSet.close();
> }
> catch (Exception ignored) {
> }
> }
> if (statement != null && !multiStatementDriver) {
> try {
> statement.close();
> }
> catch (Exception ignored) {
> }
569c568,573
< catch (Exception ignored) {
---
> if (preparedStatement != null) {
> try {
> preparedStatement.close();
> }
> catch (Exception ignored) {
> }
572d575
< resultSet = null;
657,670c660,691
< private Statement getStatement(Connection connection) throws Exception {
< // get a statement and add it to our collection of statements We are using a collection so that we ensure all statements we open are properly closed.
< try {
< Statement statement = connection.createStatement();
< statements.add(statement);
< return statement;
< }
< catch (Exception e) {
< e.printStackTrace();
< log.error("connection=\"" + connection + "\"");
< log.error("error in getStatement", e);
< throw e;
< }
< }
---
> private Statement getStatement(Connection connection) throws Exception {
> try {
> // if-else for drivers, which can not have multiple ResultSet-s per one Statement
> if (!multiStatementDriver) {
> return connection.createStatement();
> }
> else {
> if (globalStatement == null) {
> globalStatement = connection.createStatement();
> }
> return globalStatement;
> }
> }
> catch (Exception e) {
> e.printStackTrace();
> log.error("connection=\"" + connection + "\"");
> log.error("error in getStatement", e);
> throw e;
> }
> }
>
> private PreparedStatement getPreparedStatement(Connection connection, String sqlSelect) throws Exception {
> try {
> return connection.prepareStatement(sqlSelect);
> }
> catch (Exception e) {
> e.printStackTrace();
> log.error("connection=\"" + connection + "\", sqlSelect=\"" + sqlSelect + "\"");
> log.error("error in getPreparedStatement", e);
> throw e;
> }
> }
681c702
< private ResultSet getResultSet(Connection connection, String sqlSelect) throws Exception {
---
> private ResultSet getResultSet(Statement statement, String sqlSelect) throws Exception {
684,691d704
< // if-else for drivers, which can not have multiple ResultSet-s per one
< // Statement
< if (!multiStatementDriver) {
< statement = getStatement(connection);
< }
< if (statement == null) {
< statement = getStatement(connection);
< }
695c708
< log.error("connection=\"" + connection + "\", sqlSelect=\"" + sqlSelect + "\", multiStatementDriver=\"" + multiStatementDriver + "\"");
---
> log.error("statement=\"" + statement + "\", sqlSelect=\"" + sqlSelect + "\", multiStatementDriver=\"" + multiStatementDriver + "\"");
712c725
< private ResultSet getResultSet(Connection connection, String sqlSelect, ArrayList paramVals) throws Exception {
---
> private ResultSet getResultSet(PreparedStatement preparedStatement, ArrayList paramVals) throws Exception {
716d728
< preparedStatement = connection.prepareStatement(sqlSelect);
726c738
< log.error("connection=\"" + connection + "\", sqlSelect=\"" + sqlSelect + "\", multiStatementDriver=\"" + multiStatementDriver + "\"");
---
> log.error("connection=\"" + connection + "\", multiStatementDriver=\"" + multiStatementDriver + "\"");
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thank-you for this terrific piece of software!
I was having difficulty making it work for MySQL. The issue turned out to be around line 250 where you're calling XPathHelper.getBoolean(), which returns true if the xpath matches any node, regardless of the node's value. I changed this to call XPathHelper.getString() and to compare the node's value to true.
Along the way I did a bit of refactoring so that statements for non-multiStatementDriver's are cleaned up incrementally rather than being pushed onto a stack. Here's the diff (from the version in cvs, not the released version) in case you're interested.