Menu

No code generation with MySql

Help
rjemmons
2007-11-16
2013-04-25
  • rjemmons

    rjemmons - 2007-11-16

    I am able to get good Sql2java code generation for my database schema using HSQLDB, but not with MySql.  I would appreciate any help.

    Sql2java does not seem to find my table list when I use MySql.  The tables definetly exist in MySql.  I can display their contents with with an Ant task I created.

    All I do to switch between database managers is to edit my database.properties file:

    For HSQLDB

    jdbc.type=hsql
    jdbc.driver=org.hsqldb.jdbcDriver
    jdbc.url=jdbc:hsqldb:hsql://localhost
    jdbc.username=sa
    jdbc.password=
    jdbc.schema=null
    #-- HSQL ------
    generatedkey.retrieve=after
    generatedkey.statement=CALL IDENTITY()

    For Mysql:

    jdbc.type=mysql
    jdbc.driver=com.mysql.jdbc.Driver
    jdbc.url=jdbc:mysql://localhost:3306
    jdbc.username=root
    jdbc.password=mypwd
    jdbc.schema=myDatabaseName
    #-- IF YOU USE A JDBC 3.0 DRIVER (works with mysql, ORACLE 9, etc..) ------
    generatedkey.retrieve=auto
    generatedkey.statement=

    With Hsqldb, I get good code generation, but with MySql, no code is generated for my tables.  Here is the output from ant generate using MySql:

    Buildfile: C:\document\eclipse\java\Sql2javaAuth\build.xml
    generate.check:
    generate.code:
         [echo] generate.code, lib=C:\document\eclipse\java\Sql2javaAuth/lib
    [sql2java] GenerationTask: C:\document\eclipse\java\Sql2javaAuth/src/config/auth.properties
    [sql2java] Connecting to root on jdbc:mysql://localhost:3306 ...
    [sql2java]     Connected.
    [sql2java]     Database server :MySQL.
    [sql2java] Loading table list according to pattern % ...
    [sql2java] Loading columns ...
    [sql2java] Database::loadPrimaryKeys
    [sql2java] Loading imported keys ...
    [sql2java] Loading indexes ...
    [sql2java] Loading procedures ...
    [sql2java] getLoadingPath = .,src/templates/velocity/includes,
    [sql2java] Generating template src/templates/velocity//db/perschema/database.documentation.list.html.vm
    [sql2java]  .... writing to src/\web/database/\index.html
    [sql2java]     web/database/\index.html done.
    [sql2java] Generating template src/templates/velocity//db/perschema/database.documentation.overview.html.vm
    [sql2java]  .... writing to src/\web/database/\overview.html
    [sql2java]     web/database/\overview.html done.
    [sql2java] Generating template src/templates/velocity//db/perschema/database.documentation.txt.vm
    [sql2java]  .... writing to src/\java\com\aurigen\sql2javaauth\database.txt
    [sql2java]     java\com\aurigen\sql2javaauth\database.txt done.
    [sql2java] Generating template src/templates/velocity//db/perschema/graphviz/ant.graphviz.xml.vm
    [sql2java]  .... writing to src/\web/database/graphviz/\build.xml
    [sql2java]     web/database/graphviz/\build.xml done.
    [sql2java] Generating template src/templates/velocity//db/perschema/graphviz/full.graphviz.vm
    [sql2java]  .... writing to src/\web/database/graphviz/\full.graphviz
    [sql2java]     web/database/graphviz/\full.graphviz done.
    [sql2java] Generating template src/templates/velocity//db/perschema/graphviz/overview.graphviz.vm
    [sql2java]  .... writing to src/\web/database/graphviz/\overview.graphviz
    [sql2java]     web/database/graphviz/\overview.graphviz done.
    [sql2java] Generating template src/templates/velocity//db/perschema/sql2java.xml.vm
    [sql2java]  .... writing to src/\\\/config\sql2java.generated.xml
    [sql2java]     \\/config\sql2java.generated.xml done.
    [sql2java] Generating template src/templates/velocity//java/perschema/database.properties.vm
    [sql2java]  .... writing to src/\java\com\aurigen\sql2javaauth\database.properties
    [sql2java]     java\com\aurigen\sql2javaauth\database.properties done.
    [sql2java] Generating template src/templates/velocity//java/perschema/exception/dao.exception.java.vm
    [sql2java]  .... writing to src/\java\com\aurigen\sql2javaauth\exception\DAOException.java
    [sql2java]     java\com\aurigen\sql2javaauth\exception\DAOException.java done.
    [sql2java] Generating template src/templates/velocity//java/perschema/exception/data.access.exception.java.vm
    [sql2java]  .... writing to src/\java\com\aurigen\sql2javaauth\exception\DataAccessException.java
    [sql2java]     java\com\aurigen\sql2javaauth\exception\DataAccessException.java done.
    [sql2java] Generating template src/templates/velocity//java/perschema/exception/data.retrieval.exception.java.vm
    [sql2java]  .... writing to src/\java\com\aurigen\sql2javaauth\exception\DataRetrievalException.java
    [sql2java]     java\com\aurigen\sql2javaauth\exception\DataRetrievalException.java done.
    [sql2java] Generating template src/templates/velocity//java/perschema/exception/object.retrieval.exception.java.vm
    [sql2java]  .... writing to src/\java\com\aurigen\sql2javaauth\exception\ObjectRetrievalException.java
    [sql2java]     java\com\aurigen\sql2javaauth\exception\ObjectRetrievalException.java done.
    [sql2java] Generating template src/templates/velocity//java/perschema/exception/optimistic.locking.exception.java.vm
    [sql2java]  .... writing to src/\java\com\aurigen\sql2javaauth\exception\OptimisticLockingException.java
    [sql2java]     java\com\aurigen\sql2javaauth\exception\OptimisticLockingException.java done.
    [sql2java] Generating template src/templates/velocity//java/perschema/generated.bean.java.vm
    [sql2java]  .... writing to src/\java\com\aurigen\sql2javaauth\GeneratedBean.java
    [sql2java]     java\com\aurigen\sql2javaauth\GeneratedBean.java done.
    [sql2java] Generating template src/templates/velocity//java/perschema/manager.java.vm
    [sql2java]  .... writing to src/\java\com\aurigen\sql2javaauth\Manager.java
    [sql2java]     java\com\aurigen\sql2javaauth\Manager.java done.
    generate.graphs.check:
    generate.graphs:
    generate:
    BUILD SUCCESSFUL
    Total time: 2 seconds

     
    • rjemmons

      rjemmons - 2007-11-16

      I got the code generation with MySql.  I'm posting this in case others run into similar problems.

      Sql2java could not generate the code because I had a property wrong:

      Correct for MySql:
      jdbc.url=jdbc:mysql://localhost:3306/myDatabasename
      Incorrect for MySql (what I had):
      jdbc.url=jdbc:mysql://localhost:3306

      I had it wrong because MySql threw an error when I ran ant database.create if the database did not exist.  I had to use the incorrect jdbc.url to create a database when one did not exist.  One way to work around this is to manually create an empty database (just an empty directory) in the MySql data directory.  Then you can run ant database.create to create your tables.

      I also thought of adding a new property:

      jdbc.urlMySql=jdbc:mysql://localhost:3306

      and using it in the database.create task, but this may cause problems with other database managers?

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.