Wednesday, December 26, 2012

1Z0-895 Java Platform, Enterprise Edition 6 Enterprise JavaBeans Developer Certified Expert Exam


I passed in Oracle EJB Developer certification.

I studied the book EJB 3 In Action (http://www.amazon.com/EJB-3-Action-Debu-Panda/dp/1933988347). No need to study JPA chapters. The problem with this book is that it is about EJB 3 only, so it is necessary to study EJB 3.1 topics in another sources. This book is not so good, but it is starting point.

After reading the book I started doing mocks. I used Enthuware (http://enthuware.com/index.php/mock-exams/oracle-certified-expert/oceejbd-ejb-6). It is excellent and very similar as the exam.

As doubts were emerging during the mock I studied JSR 318 (http://jcp.org/en/jsr/detail?id=318). The JSR is not good to be used as initial source of learning, it is not a teaching document, but it is the best source of information.

The study method I have adopted is to learn by repetition. I did the initial mock and four standards mocks. For every mock, I did it by the first time, after reviewed all questions and then retraced the mock. The first time the grade was always low, but repeating grade was high.

The time it takes to make the mock by the first time is around 2 hours. The review needs 3 to 4 hours because that's when you really study. Repeating the mock takes 1 hour because you are already dominating the subject. It is important not to memorize the answers, but rather try to explain them.

To cover all topics of exam is necessary to make all the 4 standards mocks because the distribution of the questions is not 100%.

When finished doing the mocks, redid the questions I never hit (neither the first nor the repetition) for all mocks. It has a feature for this in Enthuware software.

I passed with 90% and I was pleased with the time spent to study.

Good luck in your studies.

How to limit the number of records returned in a SQL query


There is no a SQL standard to limit the number of records returned in a query, ie, each vendor implements this functionality in its own way.

Here's a summary on how to do this for some vendors:

DB2 -- select * from table fetch first 10 rows only 
Informix, InterBase/Firebird, SKIP  -- select first 10 * from table 
Microsoft SQL Server and Access -- select top 10 * from table 
MySQL, PostgreSQL, SQLite, HSQL/H2 -- select * from table limit 10 
Oracle -- select * from table where rownum <= 10

Oracle Note:
If the query has "group by" or "order by" rownum must be supplied:

Ex:
SELECT a, b, c
FROM
( SELECT a, b, c, ROWNUM rn
FROM
( SELECT a, b, c FROM RECORD 
WHERE AVAIL='Y"
ORDER BY DATE DESC
)
WHERE ROWNUM <= 25
)
WHERE rn >= 21;

References:



Wednesday, March 14, 2012

How to encrypt using MD5 with a Java code example

Using the code bellow it is possible to generate a MD5 Hash related to strings:


    public static String encrypt(String sign) {   
    
        try {   
           java.security.MessageDigest md =   
              java.security.MessageDigest.getInstance("MD5");   
           md.update(sign.getBytes());   
           byte[] hash = md.digest();   
           StringBuffer hexString = new StringBuffer();   
           for (int i = 0; i < hash.length; i++) {   
              if ((0xff & hash[i]) < 0x10)   
                 hexString.append(   
                    "0" + Integer.toHexString((0xFF & hash[i])));   
              else   
                 hexString.append(Integer.toHexString(0xFF & hash[i]));   
           }   
           sign = hexString.toString();   
        }   
        catch (Exception nsae) {   
           nsae.printStackTrace();   
        }   
        return sign;   
     }  


Here you have a MD5 Hash Generator online:
http://www.miraclesalad.com/webtools/md5.php

Wednesday, January 18, 2012

How to show only one header in sqlplus

When you have to use sqlplus and want to avoid showing table header each n rows returned, you can use the command bellow to show only one header:


set pagesize 0   -- only one header row

Another useful commands:
set colsep ,     -- separate columns with a comma
set trimspool on -- remove trailing blanks
set headsep off  -- this may or may not be useful...depends on your headings.
set linesize X   -- X should be the sum of the column widths

sqlplus reference: http://psoug.org/reference/sqlplus.html
How to create a csv file from sqlplus output: http://stackoverflow.com/questions/643137/how-do-i-spool-to-a-csv-formatted-file-using-sqlplus


Wednesday, January 4, 2012

How to generate Java classes for Hibernate from MySql database tables using Eclipse Indigo


  1. Install JBoss Tools on Eclipse using update site
    In Eclipse Indigo, on menu bar, click Help / Install new Software
    Paste this address in Work with text field and click Add... http://download.jboss.org/jbosstools/updates/development/indigo/
    The mandatory plugin is JBoss Data Services / Hibernate tools, but it is good to install all of them
  2. Create a Hibernate Configuration
    Open Hibernate Perspective
    In Hibernate Configurations panel, right click in a empty space and go to Add Configuration
    In Project field, select the project where Java classes will be created.
    In Database Connection combo box select an existent MySql connection or create a new one clicking on New button.
    In Property file field, click in Setup / Create new
    In Configuration file field, click in Setup / Create new
    Click OK
  3. Run Hibernate Code Generation
    Edit hibernate.cfg.xml file. Remove name property on session-factory tag. Let it with no attributes.
    Add hibernate-tools.jar to the project classpath. It can be found at <eclipse installation folder>\plugins\org.jboss.tools.hibernateextension4_0_3.4.0.v20111213-1944-H40-M5\lib\tools
    On Hibernate perspective, on menu bar, click Run / Hibernate Code Generation /  Hibernate Code Generation Configurations
    In Console configuration, select the just created configuration
    In Output directory, select the source root folder
    In Package, type desired package
    In revenge.xml, click Setup / Create new
    In reveng. strategy, Browse to the class org.hibernate.cfg.reveng.DefaultReverseEngineeringStrategy
    Click Run button
  4. Check generated classes out
    Open Java EE perspective
    Refresh project files
    See that entity and DAO classes were generated