1. Download

  1. First, make sure you have the Java Development Kit installed. OneWebSQL™ for JDBC requires Java 1.6 or higher.
  2. If you want to use the Maven plugin, make sure you have Maven installed. The OneWebSQL™ for JDBC Maven plugin requires Maven 2.
  3. Download the OneWebSQL™ for JDBC zip file from http://onewebsql.com/download.

    The zip file includes:
    • INSTALL.txt - installation guide
    • README.txt - project description
    • install.sh, install.bat - installation scripts
    • gen.sh, gen.bat - generation scripts
    • example folder - contains sample HSQLDB database and example Maven project which demonstrates how to use OneWebSQL™ for JDBC
    • several .jar files - includes OneWebSQL™ for JDBC itself and related libraries.

2. Installation

2.1. Installation with Maven

If you want to use OneWebSQL™ with Maven you need to install the OneWebSQL™ code generation plugin.

2.1.1. Installation in Linux

  1. Unzip the archive.
  2. Run:
    ./install.sh
    
    The script installs the plugin in your local repository. You will see the following output as the installer is running:
    Installing OneWeb SQL Database -> Java Generator, version 1.0.3
    [INFO] Scanning for projects...
    [INFO] Searching repository for plugin with prefix: 'install'.
    
    ...
    
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESSFUL
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: < 1 second
    [INFO] Finished at: Thu Feb 23 13:52:15 CET 2012
    [INFO] Final Memory: 3M/77M
    [INFO] ------------------------------------------------------------------------
    
  3. The OneWebSQL™ for JDBC Maven plugin is now installed.

2.1.2. Installation in Windows

  1. Unzip the archive.
  2. Run:
    install.bat
    
    The script installs the plugin in your local repository. You will see the following output as the installer is running:
    Installing OneWeb SQL Database -> Java Generator, version 1.0.3
    [INFO] Scanning for projects...
    [INFO] Searching repository for plugin with prefix: 'install'.
    
    ...
    
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESSFUL
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: < 1 second
    [INFO] Finished at: Thu Feb 23 13:52:15 CET 2012
    [INFO] Final Memory: 3M/77M
    [INFO] ------------------------------------------------------------------------
    
  3. The OneWebSQL™ for JDBC Maven plugin is now installed.

2.2. Installation as a standalone tool

Just unzip the archive and you're done.

3. Generate classes

3.1. Class generation with Maven

If you use Maven 2, you may use the Maven plugin version of OneWebSQL™ for JDBC.

3.1.1. Example project

In the example directory, there is a sample Maven project and a sample HSQLDB database. To compile the project, go to the example directory and run:

mvn compile

This will generate the same classes that come with the standalone version. The source files are generated in the target/generated-sources/onewebsql directory.

3.1.2. Set up your project

To use the OneWebSQL™ for JDBC Maven plugin, you will need to edit your project's pom.xml file. Editing the pom.xml file will enable you to set up the model file and target Java package properties.

  1. To add maven-onewebsql-db2java-plugin to your project, add the following lines to your pom.xml file, in the <plugins> section:

    ...
      <plugins>
    ...
        <plugin>
           <groupId>com.onewebsql</groupId>
           <artifactId>maven-onewebsql-db2java-plugin</artifactId>
           <version>1.0.3</version>
           <dependencies>
                <!-- JDBC driver -->
                <dependency>
                    <groupId>org.hsqldb</groupId>
                    <artifactId>hsqldb</artifactId>
                    <version>2.2.8</version>
                </dependency>
           </dependencies>
           <executions>
                <execution>
    	        <id>common</id>
    		<phase>generate-sources</phase>
    		<goals>
    		    <goal>generate</goal>
    		</goals>
    		<configuration>
    		    <!-- database connection -->
    		    <jdbc_url>jdbc:hsqldb:file:demo-db</jdbc_url>
    		    <connection_properties>
    		        <property>
                                 <name>user</name>
    			     <value>SA</value>
    			</property>
    			<property>
                                 <name>password</name>
    			     <value>PASSWORD</value>
    			</property>
    		     </connection_properties>
    		     <!-- database schemas to generate tables from -->
    		     <schemas>
    		         <param>PUBLIC</param>
    		     </schemas>
    		     <!-- name of the Java package for generated classes -->
    		     <java_default_package>com.yourdomain.example_package</java_default_package>
    		     <!-- name of the JDBC driver to use -->
    		     <jdbc_driver>org.hsqldb.jdbcDriver</jdbc_driver>
    		</configuration>
    	     </execution>
             </executions>
        </plugin>
    ...
    </plugins>
    ...
    
  2. Ensure that you are using Java 1.6 or higher by adding these lines in the <plugins> section as well:
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.3.2</version>
        <configuration>
            <source>1.6</source>
        </configuration>
    </plugin>
    
  3. Compile the project by running this line of code:
    mvn compile
    

3.1.3. Eclipse integration

Once the source files have been generated, run:

mvn eclipse:eclipse

and refresh your Eclipse project. The generated classes will be marked as source folders in Eclipse. You can use them in your code.

3.2. Class generation with standalone tool

In Linux, run:

./gen.sh

In Windows, run:

gen.bat

The script connects to the sample HSQLDB database and generates the .java files. The source files are generated in the target/generated-sources/onewebsql directory.

Copy the generation script into your project folder and adjust its contents as needed.

4. OneWebSQL™ for JDBC documentation

You can find more information on how to generate Java code with OneWebSQL™ for JDBC in OneWebSQL™ Reverse Engineering Guide.