Saturday, October 26, 2013

015. JAVADB-DERBY: CREATE FUNCTION

Trust me, it is complicated. But, it's cool.


  • Previously, create .jar file. Example:

    package function;


    public class parameters {
         private static String stcPrm1="";

         public static String setPrm1(String dnString){
            stcPrm1=dnString;
            return stcPrm1;
         }

         public static String getPrm1(){return stcPrm1;}
    }

    Compile to .jar file (example: DDA_derby.jar).

  • Register that .jar to Derby:
    Using Derby GUI, run query:
    CALL sqlj.install_jar ('C:/myfolder/DDA_derby.jar', 'APP.DDA_derby', 0);

  • Set classpath:
    CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY(
    'derby.database.classpath', 'APP.DDA_derby');


  • Create function:
    CREATE FUNCTION APP.SETPARAM1(PARAM1 VARCHAR(200))
    RETURNS VARCHAR(200)
    PARAMETER STYLE JAVA
    NO SQL LANGUAGE JAVA
    EXTERNAL NAME 'function.parameters.setPrm1';

    CREATE FUNCTION APP.GETPARAM1()
    RETURNS VARCHAR(200)
    PARAMETER STYLE JAVA
    NO SQL LANGUAGE JAVA
    EXTERNAL NAME 'function.parameters.getPrm1';

Deleting .jar:
CALL sqlj.remove_jar ('APP.DDA_derby', 0);

Replacing .jar:
CALL sqlj.replace_jar('C:/myfolder/DDA_derby.jar', 'APP.DDA_derby');


Test:
SELECT * FROM MYSCHEMA.MYTABLE WHERE MYFIELD=APP.SETPARAM1('ABCDE');


Parameterize View:
CREATE VIEW VW AS SELECT * FROM MYSCHEMA.MYTABLE WHERE MYFIELD=APP.GETPARAM1();

SELECT VW.*, (VALUES APP.SETPARAM1('ABCDE')) FROM VW;



Do you want to try?

Saturday, October 12, 2013

014. JAVADB-DERBY: GUI



These are the reasons why I am choosing JavaDB-Derby database:
  1. Multiplatform and free.
  2. Without database installation.
  3. It can be an embedded database, like as Ms. Access. Just copy-paste a database folder for backup.
  4. Support relationship.
  5. It has view and sequence.
  6. It has function, procedure, and trigger. Trust me, they 're hard.
  7. It can be attached a custom function from .jar. So, it can show a form/frame from .jar with SQL sintax.
  8. Autonumber datatype can be restart to number 1.
  9. It has BOOLEAN datatype.
  10. It has database security.
  11. Easily upsize to be a server database. Just moving that database folder to derbyhome/bin folder. Then run StartNetworkServer.bat or StartNetworkServer.sh. And easily downsize to be an embedded database.
  12. It can be stored in .jar file. Though there are a few limitation, like as: data can't be added, editted, or deleted; No database security; Using APP schema only.

This GUI using derby.jar version 10.8.1.2. If it is different from your version, replace it with your derby.jar and your derbyclient.jar.

We can download a simple "JAVADB-DERBY GUI" from this link, or from top-right corner of this page. On GoogleDrive page, choose menu: File -> Download.

We can read Derby reference from http://db.apache.org/derby/docs/10.2/ref
For example we can read 008. ADD DATABASE TO JTABLE (PART 1).

Thanks a lot, to Apache Derby (Apache Software Foundation), and to all.










Thursday, October 3, 2013

013. iReport: SETTING DATABASE CONNECTION

Requirements:
- download derby.jar (database library).
- download sample database (Java DB - Apache Derby 10.8.1.2)On GoogleDrive page, choose menu: File -> Download. This file contain database=DANIANI_DB; user=daniani_user; password=daniani_pwd; schema=SCH. Then extract it in a certain location.

  1. Run i-Report application
  2. Click menu Window - Services


  3. Right click Drivers node, select New Driver...



  4. Click Add button, then search derby.jar.

  5. We 'll see there is a new driver, then right click, select Connect Using...
  6. Search the Derby database location, for example (case-sensitive) database name = DANIANI_DB, user = daniani_user, password = daniani_pwd



  7. On tab Advanced, select schema to SCH (my schema).


  8. The connection has been built. Double click the connection then rightclick PARENT table, choose view data ...


  9. On toolbar click Datasource button.


  10. Choose Netbeans Database JDBC connection


  11. set Name = whatever (example: DDA), and choose Connection.


  12. We 'll see, then Close.


  13. The datasource 'll be shown. This step for our next discussion about i-Report.