java hosting


Jenny the database code generator - FAQ

Questions

Answers

    What is Jenny?

    Jenny is a Java program that generates java code specific to your database. The Jenny home page describes the Jenny application in more detail.

    For each table and view in a given database, Jenny will create a java source class file. Each of these classes will provide a collection of general purpose methods for working with the table/view. They will also provide a list of all the column names, the table/view name and an inner class called Row that can be used to manipulate a single row in the table.

    Why do you call it Jenny?

    We wanted something JavaRanch-ish. Acronyms didn't seem to be working out. The key words would be: Simple Database Access Facade Row Gateway Pattern ...

    We briefly considered "Tractor" because it's an engine that will go in the Code Barn.

    Then we thought, "It's a code "Generator", how about "Jenny"" and the name stuck. This name also goes along with the precedent set in other JavaRanch code, names like "Buffy" the StringBuffer, and "Percy" the persistent Object.

    Tell us a little bit of Jenny's history

      First public release of version 0.8 - May 26, 2003 (Announcement)

    How do I install Jenny?

    How do I use Jenny?

    Run Jenny every time your database changes.

    • From the command prompt type:
          java com.javaranch.jenny.dev.Jenny  db.properties 
      where db.properties is the properties file you wish to use for this database.

      Other ways to run Jenny include:

    • Now that you've created your "personalized" files, you are ready to use them.

      You should be able to see a java source file for each of your tables in your database. Compile and use the generated source as if you wrote it yourself!

      For example:

        Let's say that you have a database named "rentals". Within the rentals database you have tables named "videos", "compactDisks", "booksOnTape". After you run Jenny, you should see a subdirectory named rentals (the subdirectory is defined by the properties file) which contains classes named "Videos", "CompactDisks", and "BooksOnTape". Each of these classes contains methods with the same signature as the methods in DBFacade, which have been overridden. Now you can create a method in your code like:
            // pass in an serial number and get back the title of the video that you are searching for.
            private String getVideoTitle( int serialNumber )
            {
                return VideosTable.getRow( serialNumber ).getTitle();
            }
              
        and you won't have to worry about getting the wrong thing back because someone changed the name of the column from "Title" to "Titles" or having to change the code in the getTitle() method from
            out.print( rs.getString( "Title" ) );
              
        to
            out.print( rs.getString( "Titles" ) );
              
        everywhere you've used that column name.

      More examples can be found here.

    What if I don't yet have a database?

    Ask your dba to create one, or, if you are learning about databases and jdbc, create one yourself by following the instructions on this page, where you will learn how to set up MySQL (the world's most popular open source (free) database, recognized for its speed and reliability), and create a database and a table using SQL.

    What other ways can I run Jenny besides from the command line?

    From your IDE:

      Put jenny-dev.jar and jenny-prod.jar into the classpath your IDE uses (usually in a different place than the command line classpath). Some IDE's may have a special place to place jar files instead, such as in "lib" or "libraries"

      Define the "Main Class" (a.k.a "Target" or "command") as

          com.javaranch.jenny.dev.Jenny
      Define the "Program Parameters" as
          db.properties
      where db.properties is a properties file that describes where Jenny should find your database.

      Use the "Run" command.

    From an icon on your Windows desktop:

      Create a shortcut for the cmd.exe program on your desktop. Right click the icon and choose "Properties".

      Define the "Target" as

          java.exe com.javaranch.jenny.dev.Jenny db.properties
      where db.properties is a properties file that describes how Jenny should find your database.
      For example, in the "Target" entry, you might see
          %SystemRoot%\system32\java.exe com.javaranch.jenny.dev.Jenny com/ javaranch/db/jenny.properties
      Define the "Start in" as your working directory.
      For example:
          "C:\Java"
      Click OK.

      Double click the icon. Jenny will open a window, run, creating the necessary files, and close the window.

    In a build script, Ant script, or batch file:

      Make sure your classpath includes jenny-dev.jar and jenny-prod.jar.

      Include the line

          java com.javaranch.jenny.dev.Jenny db.properties
      where db.properties is the properties file you wish to use for this table in the script or bat file.



Page maintained by Marilyn de Queiroz