MySQL connection problem following DBUnit FAQ Java Program Example

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

MySQL connection problem following DBUnit FAQ Java Program Example

Andrew Wilkie
I'm setting up DBUnit to work with my Canoo webtests by following:
http://dbunit.sourceforge.net/howto.html#canoo and
http://dbunit.sourceforge.net/howto.html#createdataset

When creating the dataset by using the export Java program listed here
http://dbunit.sourceforge.net/faq.html#extract

When executing this statement:
Connection jdbcConnection = DriverManager.getConnection(
        "jdbc:mysql://localhost:3306/test_database", "test", "testpassword");

I'm getting the following stack trace:
com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error
in your SQL syntax; check the manual that corresponds to your MySQL
server version for the right syntax to use near
'????????????????????????????????' at line 1
   at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)
   at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985)
   at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631)
   at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723)
   at com.mysql.jdbc.Connection.execSQL(Connection.java:3277)
   at com.mysql.jdbc.Connection.configureClientCharacterSet(Connection.java:2525)
   at com.mysql.jdbc.Connection.initializePropsFromServer(Connection.java:4139)
   at com.mysql.jdbc.Connection.createNewIO(Connection.java:2789)
   at com.mysql.jdbc.Connection.<init>(Connection.java:1555)
   at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285)
   at java.sql.DriverManager.getConnection(libgcj.so.90)
   at java.sql.DriverManager.getConnection(libgcj.so.90)
   at DatabaseExport.main(DatabaseExport.java:43)

The SQL of  '????????????????????????????????' at line 1 is a problem
but I'm not sure what is causing this.

Any help or pointers would be greatly appreciated.

------------------------------------------------------------------------------
_______________________________________________
dbunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/dbunit-user
Reply | Threaded
Open this post in threaded view
|

Re: MySQL connection problem following DBUnit FAQ Java Program Example

Matthias Gommeringer
Hi Andrew,

do you use the latest MySql JDBC driver?

Do you invoke

Class.forName("com.mysql.jdbc.Driver").newInstance()

before doing the DriverManager.getConnection()?

regards,
matthias


> -----Ursprüngliche Nachricht-----
> Von: "Andrew Wilkie" <[hidden email]>
> Gesendet: 26.06.09 01:33:20
> An: [hidden email]
> Betreff: [dbunit-user] MySQL connection problem following DBUnit FAQ Java Program Example


> I'm setting up DBUnit to work with my Canoo webtests by following:
> http://dbunit.sourceforge.net/howto.html#canoo and
> http://dbunit.sourceforge.net/howto.html#createdataset
>
> When creating the dataset by using the export Java program listed here
> http://dbunit.sourceforge.net/faq.html#extract
>
> When executing this statement:
> Connection jdbcConnection = DriverManager.getConnection(
> "jdbc:mysql://localhost:3306/test_database", "test", "testpassword");
>
> I'm getting the following stack trace:
> com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error
> in your SQL syntax; check the manual that corresponds to your MySQL
> server version for the right syntax to use near
> '????????????????????????????????' at line 1
>    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)
>    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985)
>    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631)
>    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723)
>    at com.mysql.jdbc.Connection.execSQL(Connection.java:3277)
>    at com.mysql.jdbc.Connection.configureClientCharacterSet(Connection.java:2525)
>    at com.mysql.jdbc.Connection.initializePropsFromServer(Connection.java:4139)
>    at com.mysql.jdbc.Connection.createNewIO(Connection.java:2789)
>    at com.mysql.jdbc.Connection.<init>(Connection.java:1555)
>    at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285)
>    at java.sql.DriverManager.getConnection(libgcj.so.90)
>    at java.sql.DriverManager.getConnection(libgcj.so.90)
>    at DatabaseExport.main(DatabaseExport.java:43)
>
> The SQL of  '????????????????????????????????' at line 1 is a problem
> but I'm not sure what is causing this.
>
> Any help or pointers would be greatly appreciated.
>
> ------------------------------------------------------------------------------
> _______________________________________________
> dbunit-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/dbunit-user
>


______________________________________________________
GRATIS für alle WEB.DE-Nutzer: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://movieflat.web.de


------------------------------------------------------------------------------
_______________________________________________
dbunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/dbunit-user
Reply | Threaded
Open this post in threaded view
|

Re: MySQL connection problem following DBUnit FAQ Java Program Example

Andrew Wilkie
Hi Matt.

I updated the MySQL JDBC driver from 5.0.8 to 5.1.7 and added the new jar to my Eclipse build path.

I added the method call as shown below (which prompted me to catch a couple more exceptions) however I still get the '?????????????' error.

So it is connecting to the MySQL server OK but there are some SQL statements being sent by DBUnit that I can't see.

BTW, the SQL viewer tool link listed at FAQ http://www.dbunit.org/faq.html#p6spy appears to be 'broken' - http://www.p6spy.com/skip_survey_results3.php.

I've attached the java source code below.

Cheers.
Andrew


/**
 *
 */
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.SQLException;

import org.dbunit.DatabaseUnitException;
import org.dbunit.database.AmbiguousTableNameException;
import org.dbunit.database.DatabaseConnection;
import org.dbunit.database.IDatabaseConnection;
import org.dbunit.database.QueryDataSet;

import org.dbunit.dataset.xml.FlatXmlDataSet;

import org.dbunit.dataset.DataSetException;
//import org.dbunit.dataset.IDataSet;
//import org.dbunit.database.search.TablesDependencyHelper;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;


/**
 * @author andrew
 *
 */
public class DatabaseExport {

    /**
     * @param args
     */
    public static void main(String[] args) {

        try {
            // database connection
            IDatabaseConnection connection;
            Class.forName("com.mysql.jdbc.Driver").newInstance();
            Connection jdbcConnection = DriverManager.getConnection(
                    "jdbc:mysql://localhost:3306/test_database", "test", "testpassword");
            connection = new DatabaseConnection(jdbcConnection);

            // partial database export
            QueryDataSet partialDataSet = new QueryDataSet(connection);
            partialDataSet.addTable("subscriber", "SELECT * FROM subscriber WHERE COL='id'");
            //partialDataSet.addTable("subscriber");
            FlatXmlDataSet.write(partialDataSet, new FileOutputStream("partial.xml"));
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (AmbiguousTableNameException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (DataSetException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (SecurityException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (DatabaseUnitException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        // full database export
//        IDataSet fullDataSet = connection.createDataSet();
//        FlatXmlDataSet.write(fullDataSet, new FileOutputStream("full.xml"));
//       
//        // dependent tables database export: export table X and all tables that
//        // have a PK which is a FK on X, in the right order for insertion
//        String[] depTableNames =
//          TablesDependencyHelper.getAllDependentTables( connection, "X" );
//        IDataSet depDataSet = connection.createDataSet( depTableNames );
//        FlatXmlDataSet.write(depDataSet, new FileOutputStream("dependents.xml")); 

    }
}





On Mon, Jun 29, 2009 at 6:42 PM, Matthias Gommeringer <[hidden email]> wrote:
Hi Andrew,

do you use the latest MySql JDBC driver?

Do you invoke

Class.forName("com.mysql.jdbc.Driver").newInstance()

before doing the DriverManager.getConnection()?

regards,
matthias


> -----Ursprüngliche Nachricht-----
> Von: "Andrew Wilkie" <[hidden email]>
> Gesendet: 26.06.09 01:33:20
> An: [hidden email]
> Betreff: [dbunit-user] MySQL connection problem following DBUnit FAQ Java Program Example


> I'm setting up DBUnit to work with my Canoo webtests by following:
> http://dbunit.sourceforge.net/howto.html#canoo and
> http://dbunit.sourceforge.net/howto.html#createdataset
>
> When creating the dataset by using the export Java program listed here
> http://dbunit.sourceforge.net/faq.html#extract
>
> When executing this statement:
> Connection jdbcConnection = DriverManager.getConnection(
>       "jdbc:mysql://localhost:3306/test_database", "test", "testpassword");
>
> I'm getting the following stack trace:
> com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error
> in your SQL syntax; check the manual that corresponds to your MySQL
> server version for the right syntax to use near
> '????????????????????????????????' at line 1
>    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)
>    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985)
>    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631)
>    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723)
>    at com.mysql.jdbc.Connection.execSQL(Connection.java:3277)
>    at com.mysql.jdbc.Connection.configureClientCharacterSet(Connection.java:2525)
>    at com.mysql.jdbc.Connection.initializePropsFromServer(Connection.java:4139)
>    at com.mysql.jdbc.Connection.createNewIO(Connection.java:2789)
>    at com.mysql.jdbc.Connection.<init>(Connection.java:1555)
>    at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285)
>    at java.sql.DriverManager.getConnection(libgcj.so.90)
>    at java.sql.DriverManager.getConnection(libgcj.so.90)
>    at DatabaseExport.main(DatabaseExport.java:43)
>
> The SQL of  '????????????????????????????????' at line 1 is a problem
> but I'm not sure what is causing this.
>
> Any help or pointers would be greatly appreciated.
>
> ------------------------------------------------------------------------------
> _______________________________________________
> dbunit-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/dbunit-user
>


______________________________________________________
GRATIS für alle WEB.DE-Nutzer: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://movieflat.web.de


------------------------------------------------------------------------------
_______________________________________________
dbunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/dbunit-user


------------------------------------------------------------------------------

_______________________________________________
dbunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/dbunit-user
Reply | Threaded
Open this post in threaded view
|

Re: MySQL connection problem following DBUnit FAQ Java Program Example

Luiz Eduardo Guida Valmont-2
If you debug your program from your favorite IDE, then you can attach dbunit source and manually check the SQL statements being sent to the DB server by DbUnit. All you have to do is define a break point in the proper source.

Your driver should be compatible with your db server. Well, lastest drivers are usually compatible with earlier versions of servers; still, match those versions for safety.

Regards,
Luiz

2009/6/29 Andrew Wilkie <[hidden email]>
Hi Matt.

I updated the MySQL JDBC driver from 5.0.8 to 5.1.7 and added the new jar to my Eclipse build path.

I added the method call as shown below (which prompted me to catch a couple more exceptions) however I still get the '?????????????' error.

So it is connecting to the MySQL server OK but there are some SQL statements being sent by DBUnit that I can't see.

BTW, the SQL viewer tool link listed at FAQ http://www.dbunit.org/faq.html#p6spy appears to be 'broken' - http://www.p6spy.com/skip_survey_results3.php.

I've attached the java source code below.

Cheers.
Andrew


/**
 *
 */
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.SQLException;

import org.dbunit.DatabaseUnitException;
import org.dbunit.database.AmbiguousTableNameException;
import org.dbunit.database.DatabaseConnection;
import org.dbunit.database.IDatabaseConnection;
import org.dbunit.database.QueryDataSet;

import org.dbunit.dataset.xml.FlatXmlDataSet;

import org.dbunit.dataset.DataSetException;
//import org.dbunit.dataset.IDataSet;
//import org.dbunit.database.search.TablesDependencyHelper;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;


/**
 * @author andrew
 *
 */
public class DatabaseExport {

    /**
     * @param args
     */
    public static void main(String[] args) {

        try {
            // database connection
            IDatabaseConnection connection;
            Class.forName("com.mysql.jdbc.Driver").newInstance();

            Connection jdbcConnection = DriverManager.getConnection(
                    "jdbc:mysql://localhost:3306/test_database", "test", "testpassword");
            connection = new DatabaseConnection(jdbcConnection);

            // partial database export
            QueryDataSet partialDataSet = new QueryDataSet(connection);
            partialDataSet.addTable("subscriber", "SELECT * FROM subscriber WHERE COL='id'");
            //partialDataSet.addTable("subscriber");
            FlatXmlDataSet.write(partialDataSet, new FileOutputStream("partial.xml"));
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (AmbiguousTableNameException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (DataSetException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (SecurityException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (DatabaseUnitException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        // full database export
//        IDataSet fullDataSet = connection.createDataSet();
//        FlatXmlDataSet.write(fullDataSet, new FileOutputStream("full.xml"));
//       
//        // dependent tables database export: export table X and all tables that
//        // have a PK which is a FK on X, in the right order for insertion
//        String[] depTableNames =
//          TablesDependencyHelper.getAllDependentTables( connection, "X" );
//        IDataSet depDataSet = connection.createDataSet( depTableNames );
//        FlatXmlDataSet.write(depDataSet, new FileOutputStream("dependents.xml")); 

    }
}





On Mon, Jun 29, 2009 at 6:42 PM, Matthias Gommeringer <[hidden email]> wrote:
Hi Andrew,

do you use the latest MySql JDBC driver?

Do you invoke

Class.forName("com.mysql.jdbc.Driver").newInstance()

before doing the DriverManager.getConnection()?

regards,
matthias


> -----Ursprüngliche Nachricht-----
> Von: "Andrew Wilkie" <[hidden email]>
> Gesendet: 26.06.09 01:33:20
> An: [hidden email]
> Betreff: [dbunit-user] MySQL connection problem following DBUnit FAQ Java Program Example


> I'm setting up DBUnit to work with my Canoo webtests by following:
> http://dbunit.sourceforge.net/howto.html#canoo and
> http://dbunit.sourceforge.net/howto.html#createdataset
>
> When creating the dataset by using the export Java program listed here
> http://dbunit.sourceforge.net/faq.html#extract
>
> When executing this statement:
> Connection jdbcConnection = DriverManager.getConnection(
>       "jdbc:mysql://localhost:3306/test_database", "test", "testpassword");
>
> I'm getting the following stack trace:
> com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error
> in your SQL syntax; check the manual that corresponds to your MySQL
> server version for the right syntax to use near
> '????????????????????????????????' at line 1
>    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)
>    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985)
>    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631)
>    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723)
>    at com.mysql.jdbc.Connection.execSQL(Connection.java:3277)
>    at com.mysql.jdbc.Connection.configureClientCharacterSet(Connection.java:2525)
>    at com.mysql.jdbc.Connection.initializePropsFromServer(Connection.java:4139)
>    at com.mysql.jdbc.Connection.createNewIO(Connection.java:2789)
>    at com.mysql.jdbc.Connection.<init>(Connection.java:1555)
>    at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285)
>    at java.sql.DriverManager.getConnection(libgcj.so.90)
>    at java.sql.DriverManager.getConnection(libgcj.so.90)
>    at DatabaseExport.main(DatabaseExport.java:43)
>
> The SQL of  '????????????????????????????????' at line 1 is a problem
> but I'm not sure what is causing this.
>
> Any help or pointers would be greatly appreciated.
>
> ------------------------------------------------------------------------------
> _______________________________________________
> dbunit-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/dbunit-user
>


______________________________________________________
GRATIS für alle WEB.DE-Nutzer: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://movieflat.web.de


------------------------------------------------------------------------------
_______________________________________________
dbunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/dbunit-user


------------------------------------------------------------------------------

_______________________________________________
dbunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/dbunit-user



------------------------------------------------------------------------------

_______________________________________________
dbunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/dbunit-user
Reply | Threaded
Open this post in threaded view
|

Re: MySQL connection problem following DBUnit FAQ Java Program Example

Andrew Wilkie
Thanks Luiz.

I read the documentation that came with the driver and this showed that the MySQL Connector/J URL was incorrect i.e. I needed to add '?' after the schema name and '&' between the user and password parameters.

Stepping into the debugging session showed me that there is still an issue with the URL I'm sending i.e. it parses the URL String into the various parts (host, port, user, password, etc.) but still rejects the connection with the '????????' error as before.

All the action occurs in the com.mysql.jdbc.NonRegisteringDriver.parseURL() and .connect() methods but I can't see the values of the variables with the Eclipse debugger. To insert println() statements into the source would mean having to then compile the MySQL Connector/J to byte code. When playing with this there are so many library dependencies that I gave up.

I'll head-over to the MySQL forum and see if there is some information there.

Cheers.
Andrew

On Mon, Jun 29, 2009 at 11:48 PM, Luiz Eduardo Guida Valmont <[hidden email]> wrote:
If you debug your program from your favorite IDE, then you can attach dbunit source and manually check the SQL statements being sent to the DB server by DbUnit. All you have to do is define a break point in the proper source.

Your driver should be compatible with your db server. Well, lastest drivers are usually compatible with earlier versions of servers; still, match those versions for safety.

Regards,
Luiz

2009/6/29 Andrew Wilkie <[hidden email]>

Hi Matt.

I updated the MySQL JDBC driver from 5.0.8 to 5.1.7 and added the new jar to my Eclipse build path.

I added the method call as shown below (which prompted me to catch a couple more exceptions) however I still get the '?????????????' error.

So it is connecting to the MySQL server OK but there are some SQL statements being sent by DBUnit that I can't see.

BTW, the SQL viewer tool link listed at FAQ http://www.dbunit.org/faq.html#p6spy appears to be 'broken' - http://www.p6spy.com/skip_survey_results3.php.

I've attached the java source code below.

Cheers.
Andrew


/**
 *
 */
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.SQLException;

import org.dbunit.DatabaseUnitException;
import org.dbunit.database.AmbiguousTableNameException;
import org.dbunit.database.DatabaseConnection;
import org.dbunit.database.IDatabaseConnection;
import org.dbunit.database.QueryDataSet;

import org.dbunit.dataset.xml.FlatXmlDataSet;

import org.dbunit.dataset.DataSetException;
//import org.dbunit.dataset.IDataSet;
//import org.dbunit.database.search.TablesDependencyHelper;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;


/**
 * @author andrew
 *
 */
public class DatabaseExport {

    /**
     * @param args
     */
    public static void main(String[] args) {

        try {
            // database connection
            IDatabaseConnection connection;
            Class.forName("com.mysql.jdbc.Driver").newInstance();

            Connection jdbcConnection = DriverManager.getConnection(
                    "jdbc:mysql://localhost:3306/test_database", "test", "testpassword");
            connection = new DatabaseConnection(jdbcConnection);

            // partial database export
            QueryDataSet partialDataSet = new QueryDataSet(connection);
            partialDataSet.addTable("subscriber", "SELECT * FROM subscriber WHERE COL='id'");
            //partialDataSet.addTable("subscriber");
            FlatXmlDataSet.write(partialDataSet, new FileOutputStream("partial.xml"));
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (AmbiguousTableNameException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (DataSetException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (SecurityException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (DatabaseUnitException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        // full database export
//        IDataSet fullDataSet = connection.createDataSet();
//        FlatXmlDataSet.write(fullDataSet, new FileOutputStream("full.xml"));
//       
//        // dependent tables database export: export table X and all tables that
//        // have a PK which is a FK on X, in the right order for insertion
//        String[] depTableNames =
//          TablesDependencyHelper.getAllDependentTables( connection, "X" );
//        IDataSet depDataSet = connection.createDataSet( depTableNames );
//        FlatXmlDataSet.write(depDataSet, new FileOutputStream("dependents.xml")); 

    }
}





On Mon, Jun 29, 2009 at 6:42 PM, Matthias Gommeringer <[hidden email]> wrote:
Hi Andrew,

do you use the latest MySql JDBC driver?

Do you invoke

Class.forName("com.mysql.jdbc.Driver").newInstance()

before doing the DriverManager.getConnection()?

regards,
matthias


> -----Ursprüngliche Nachricht-----
> Von: "Andrew Wilkie" <[hidden email]>
> Gesendet: 26.06.09 01:33:20
> An: [hidden email]
> Betreff: [dbunit-user] MySQL connection problem following DBUnit FAQ Java Program Example


> I'm setting up DBUnit to work with my Canoo webtests by following:
> http://dbunit.sourceforge.net/howto.html#canoo and
> http://dbunit.sourceforge.net/howto.html#createdataset
>
> When creating the dataset by using the export Java program listed here
> http://dbunit.sourceforge.net/faq.html#extract
>
> When executing this statement:
> Connection jdbcConnection = DriverManager.getConnection(
>       "jdbc:mysql://localhost:3306/test_database", "test", "testpassword");
>
> I'm getting the following stack trace:
> com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error
> in your SQL syntax; check the manual that corresponds to your MySQL
> server version for the right syntax to use near
> '????????????????????????????????' at line 1
>    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)
>    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985)
>    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631)
>    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723)
>    at com.mysql.jdbc.Connection.execSQL(Connection.java:3277)
>    at com.mysql.jdbc.Connection.configureClientCharacterSet(Connection.java:2525)
>    at com.mysql.jdbc.Connection.initializePropsFromServer(Connection.java:4139)
>    at com.mysql.jdbc.Connection.createNewIO(Connection.java:2789)
>    at com.mysql.jdbc.Connection.<init>(Connection.java:1555)
>    at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285)
>    at java.sql.DriverManager.getConnection(libgcj.so.90)
>    at java.sql.DriverManager.getConnection(libgcj.so.90)
>    at DatabaseExport.main(DatabaseExport.java:43)
>
> The SQL of  '????????????????????????????????' at line 1 is a problem
> but I'm not sure what is causing this.
>
> Any help or pointers would be greatly appreciated.
>
> ------------------------------------------------------------------------------
> _______________________________________________
> dbunit-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/dbunit-user
>


______________________________________________________
GRATIS für alle WEB.DE-Nutzer: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://movieflat.web.de


------------------------------------------------------------------------------
_______________________________________________
dbunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/dbunit-user


------------------------------------------------------------------------------

_______________________________________________
dbunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/dbunit-user



------------------------------------------------------------------------------

_______________________________________________
dbunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/dbunit-user



------------------------------------------------------------------------------

_______________________________________________
dbunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/dbunit-user
Reply | Threaded
Open this post in threaded view
|

Re: MySQL connection problem following DBUnit FAQ Java Program Example

Andrew Wilkie
Just to complete this post, I found the solution here - http://forums.mysql.com/read.php?39,259743,259743#msg-259743


On Tue, Jun 30, 2009 at 10:42 PM, Andrew Wilkie <[hidden email]> wrote:
Thanks Luiz.

I read the documentation that came with the driver and this showed that the MySQL Connector/J URL was incorrect i.e. I needed to add '?' after the schema name and '&' between the user and password parameters.

Stepping into the debugging session showed me that there is still an issue with the URL I'm sending i.e. it parses the URL String into the various parts (host, port, user, password, etc.) but still rejects the connection with the '????????' error as before.

All the action occurs in the com.mysql.jdbc.NonRegisteringDriver.parseURL() and .connect() methods but I can't see the values of the variables with the Eclipse debugger. To insert println() statements into the source would mean having to then compile the MySQL Connector/J to byte code. When playing with this there are so many library dependencies that I gave up.

I'll head-over to the MySQL forum and see if there is some information there.

Cheers.
Andrew


On Mon, Jun 29, 2009 at 11:48 PM, Luiz Eduardo Guida Valmont <[hidden email]> wrote:
If you debug your program from your favorite IDE, then you can attach dbunit source and manually check the SQL statements being sent to the DB server by DbUnit. All you have to do is define a break point in the proper source.

Your driver should be compatible with your db server. Well, lastest drivers are usually compatible with earlier versions of servers; still, match those versions for safety.

Regards,
Luiz

2009/6/29 Andrew Wilkie <[hidden email]>

Hi Matt.

I updated the MySQL JDBC driver from 5.0.8 to 5.1.7 and added the new jar to my Eclipse build path.

I added the method call as shown below (which prompted me to catch a couple more exceptions) however I still get the '?????????????' error.

So it is connecting to the MySQL server OK but there are some SQL statements being sent by DBUnit that I can't see.

BTW, the SQL viewer tool link listed at FAQ http://www.dbunit.org/faq.html#p6spy appears to be 'broken' - http://www.p6spy.com/skip_survey_results3.php.

I've attached the java source code below.

Cheers.
Andrew


/**
 *
 */
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.SQLException;

import org.dbunit.DatabaseUnitException;
import org.dbunit.database.AmbiguousTableNameException;
import org.dbunit.database.DatabaseConnection;
import org.dbunit.database.IDatabaseConnection;
import org.dbunit.database.QueryDataSet;

import org.dbunit.dataset.xml.FlatXmlDataSet;

import org.dbunit.dataset.DataSetException;
//import org.dbunit.dataset.IDataSet;
//import org.dbunit.database.search.TablesDependencyHelper;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;


/**
 * @author andrew
 *
 */
public class DatabaseExport {

    /**
     * @param args
     */
    public static void main(String[] args) {

        try {
            // database connection
            IDatabaseConnection connection;
            Class.forName("com.mysql.jdbc.Driver").newInstance();

            Connection jdbcConnection = DriverManager.getConnection(
                    "jdbc:mysql://localhost:3306/test_database", "test", "testpassword");
            connection = new DatabaseConnection(jdbcConnection);

            // partial database export
            QueryDataSet partialDataSet = new QueryDataSet(connection);
            partialDataSet.addTable("subscriber", "SELECT * FROM subscriber WHERE COL='id'");
            //partialDataSet.addTable("subscriber");
            FlatXmlDataSet.write(partialDataSet, new FileOutputStream("partial.xml"));
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (AmbiguousTableNameException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (DataSetException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (SecurityException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (DatabaseUnitException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        // full database export
//        IDataSet fullDataSet = connection.createDataSet();
//        FlatXmlDataSet.write(fullDataSet, new FileOutputStream("full.xml"));
//       
//        // dependent tables database export: export table X and all tables that
//        // have a PK which is a FK on X, in the right order for insertion
//        String[] depTableNames =
//          TablesDependencyHelper.getAllDependentTables( connection, "X" );
//        IDataSet depDataSet = connection.createDataSet( depTableNames );
//        FlatXmlDataSet.write(depDataSet, new FileOutputStream("dependents.xml")); 

    }
}





On Mon, Jun 29, 2009 at 6:42 PM, Matthias Gommeringer <[hidden email]> wrote:
Hi Andrew,

do you use the latest MySql JDBC driver?

Do you invoke

Class.forName("com.mysql.jdbc.Driver").newInstance()

before doing the DriverManager.getConnection()?

regards,
matthias


> -----Ursprüngliche Nachricht-----
> Von: "Andrew Wilkie" <[hidden email]>
> Gesendet: 26.06.09 01:33:20
> An: [hidden email]
> Betreff: [dbunit-user] MySQL connection problem following DBUnit FAQ Java Program Example


> I'm setting up DBUnit to work with my Canoo webtests by following:
> http://dbunit.sourceforge.net/howto.html#canoo and
> http://dbunit.sourceforge.net/howto.html#createdataset
>
> When creating the dataset by using the export Java program listed here
> http://dbunit.sourceforge.net/faq.html#extract
>
> When executing this statement:
> Connection jdbcConnection = DriverManager.getConnection(
>       "jdbc:mysql://localhost:3306/test_database", "test", "testpassword");
>
> I'm getting the following stack trace:
> com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error
> in your SQL syntax; check the manual that corresponds to your MySQL
> server version for the right syntax to use near
> '????????????????????????????????' at line 1
>    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)
>    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985)
>    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631)
>    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723)
>    at com.mysql.jdbc.Connection.execSQL(Connection.java:3277)
>    at com.mysql.jdbc.Connection.configureClientCharacterSet(Connection.java:2525)
>    at com.mysql.jdbc.Connection.initializePropsFromServer(Connection.java:4139)
>    at com.mysql.jdbc.Connection.createNewIO(Connection.java:2789)
>    at com.mysql.jdbc.Connection.<init>(Connection.java:1555)
>    at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285)
>    at java.sql.DriverManager.getConnection(libgcj.so.90)
>    at java.sql.DriverManager.getConnection(libgcj.so.90)
>    at DatabaseExport.main(DatabaseExport.java:43)
>
> The SQL of  '????????????????????????????????' at line 1 is a problem
> but I'm not sure what is causing this.
>
> Any help or pointers would be greatly appreciated.
>
> ------------------------------------------------------------------------------
> _______________________________________________
> dbunit-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/dbunit-user
>


______________________________________________________
GRATIS für alle WEB.DE-Nutzer: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://movieflat.web.de


------------------------------------------------------------------------------
_______________________________________________
dbunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/dbunit-user


------------------------------------------------------------------------------

_______________________________________________
dbunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/dbunit-user



------------------------------------------------------------------------------

_______________________________________________
dbunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/dbunit-user




------------------------------------------------------------------------------

_______________________________________________
dbunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/dbunit-user