A Series of Business Analytics with R — Download and Install R and RStudio — (1)

R — a software environment for statistical computing and graphics

  • Go to R-project homepage at http://www.r-project.org/, go directly to the Comprehensive R Archive Network homepage at http://cran.r-project.org/
  • On the Comprehensive R Archive Network homepage, click “Download R for Windows” or another link that matches your operating systems
  • Click “Install R for the first time” link
  • Click “Download R 3.1.2 for Windows” link to download the package. Its size is 54.1 MB.

RStudio — an integrated development environment (IDE) for R

  • Go to RStudio homepage at http://www.rstudio.com/
Posted in Uncategorized | Leave a comment

Set up Latex in Debian Wheezy

1) Using Synaptic Package Manager to install texlive packages and textworks editor

2) If using multirow.sty, need to install texlive-latex-extra package, and run the following command: >sudo texhash

3) For true type fonts,

3.1) create a new directory in /usr/share/fonts/truetype/<yourfontdir>: >sudo mkdir <yourfontdir>

3.2) copy all .ttf into the newly-created directory: >sudo mv *.tff /usr/share/fonts/truetype/<yourfontdir>/

3.3) run the following command: >sudo fc-cache -f -v

4) Run the texworks using XeLatex

Posted in Uncategorized | Leave a comment

Assign MySQL Root Password Using XAMMP Security Page

A fresh installed MySQL has a blank password. So, my scenario is that my MySQL server was installed by XAMPP 1.8.1, and I wanted to assign a root password to it. Instead of doing that in a traditional way, I chose to use XAMPP Security Page.

  1. Open XAMPP Control Panel
  2. Start Apache Server and MySQL Server
  3. Open a Web browser and point to the address: http://localhost/security
  4. Change the Language to English.
  5. Click on the link http://localhost/security/xamppsecurity.php on that page.
  6. Enter the new root password for MySQL
  7. Check on http radio button for the phpMyAdmin authentication
  8. Click on Password changing button
  9. Point browser to the address http://localhost/phpmyadmin/, you will be presented with a pop-up window for entering username and password
  10. enter “root” as a username, and whatever that you just set it up for password.
Posted in Uncategorized | Leave a comment

XAMPP 1.8.1: Cannot start Tomcat server using XAMPP Control Panel

My situation is that I was installing XAMPP 1.8.1 in Windows 8 Professional. After finished the installation, I used XAMPP Control Panel to successfully start Apache Server, MySQL Server, and Tomcat Server, respectively.

The problem was that after I stopped all those services and tried to restart them again using XAMPP Control Panel, the Tomcat server could not be started.

Problem: there is an error in the catalina_start.bat in the $XAMPP_HOME directory. So, the script cannot find the CATALINA_HOME. There are two alternative ways to fix this problem.

Fix #1: Use a text editor to edit the catalina_start.bat in the $XAMPP_HOME directory. Search for:

echo [XAMPP]: Using JDK
set "CURRENT_DIR=%cd%"

and change it to

echo [XAMPP]: Using JDK
set "CURRENT_DIR=%cd%"

Fix #2: Change the path in the Start In properties of the XAMPP Control Panel shortcut icon on the Desktop.

  1. Right click on the XAMPP Control Panel shortcut icon on the Desktop to open a context menu
  2. Click on Properties
  3. Change the Start in path from d:\myxampp\tmp\ to d:\myxampp\
  4. Click Apply and OK buttons
Posted in Uncategorized | Leave a comment

Netbeans IDE 7.2.1: Cannot load platform/lib/nbexec.dll module

I encountered the following error message: cannot load platform/lib/nbexec.dll module, when I installed Netbeans IDE 7.2.1 in Windows 8 Professional with jdk 1.7.0_09.

To fix this problem, right click on the Netbeans IDE shortcut icon on the Desktop, click on Properties, and change path in the “Start in” box from

"C:\Program Files\NetBeans 7.2.1"


"C:\Program Files\NetBeans 7.2.1\bin"

Posted in Uncategorized | Leave a comment

Hide/show a Save button in Netbeans Platform 7

When we incorporate NetBEANS Platform 7 into our application, we usually employ Action Annotations rather than layer.xml file for registering actions into a system.

For example, the code below is an implementation of closing a TopComponent. (Notes: we create a PaymentEditorTopComponent.class in org/editor/payment package, and CloseWindowAction.class in the org/action/payment package.)

@ActionID(category = "MyPaymentEditorToolbars_WindowActions",
id = "org.action.payment.CloseWindowAction")
@ActionRegistration(iconBase = "org/action/payment/cross.png",
displayName = "#CTL_CloseWindowAction")
@ActionReference(path = "Toolbars/MyPaymentEditorToolbars_WindowActions", position = 300)
@Messages("CTL_CloseWindowAction=Close Window")
public final class CloseWindowAction implements ActionListener {

public void actionPerformed(ActionEvent e) {
// TODO implement action body
PaymentEditorTopComponent tc = (PaymentEditorTopComponent)WindowManager.getDefault().findTopComponent("PaymentEditorTopComponent");
if (tc.canClose()) {

Then, we add the following code snippets into componentActivated() and componentDeactivated() of the PaymentEditorTopComponent class.

protected void componentActivated() {
Toolbar toolbar = ToolbarPool.getDefault().findToolbar("MyPaymentEditorToolbars_WindowActions");
if (!toolbar.isVisible()) {

protected void componentDeactivated() {
Toolbar toolbar = ToolbarPool.getDefault().findToolbar("MyPaymentEditorToolbars_WindowActions");
if (toolbar.isVisible()) {

By the above means, the Close Window toolbar will be displayed when the PaymentEditorTopComponent is active, and hidden when the PaymentEditorTopComponent is not active.

There is catch. From my understanding, to be able to have Action Annotation as above, the action class must implement ActionListener.

However, the Save button implements SaveCookie, not ActionListener. So, what could we do to hide and show the Save button?

What I have done is to go back to the layer.xml approach.

  1. I create a class file named MySavePaymentCookieImpl which implements SaveCookie as usual.
  2. I have InstanceContent, and fire(boolean){} as shown in the CRUD tutorial
  3. I add the following code into layer.xml

  4. <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE filesystem PUBLIC "-//NetBeans//DTD Filesystem 1.2//EN" "http://www.netbeans.org/dtds/filesystem-1_2.dtd">
    <folder name="Toolbars">
    <folder name="MyPaymentEditorToolbars_WindowActions">
    <file name="org-openide-actions-SaveAction.shadow">
    <attr name="originalFile" stringvalue="Actions/System/org-openide-actions-SaveAction.instance"/>
    <attr name="position" intvalue="300"/>

    <file name="org-openide-actions-SaveAllAction.shadow_hidden"/>

  5. Now, the key step is to inform the system to use layer.xml file by adding the following line into Module Manifest file

    OpenIDE-Module-Layer: org/editor/payment/layer.xml
Posted in Uncategorized | Leave a comment

Store image into and load image from JavaDB using EclipseLink

My successful experience on how to store and load an image (.jpg) using JavaDB+EclipseLink+Java 1.6.0_25 and NetBeans 7.0 is as follows.

  1. A table named, Customer, is used as an illustrating example. There are three attributes in this table: CustomerId, Name, and Photo.
  2. An SQL script of this table is shown below:

    create table APP.Customer
    CUSTOMER_ID INTEGER not null primary key generated always as identity (start with 1, increment by 1),
    PHOTO BLOB(2147483647)

  3. Create a database named, CustDB, through the Services tab of NetBeans IDE.
    1. In NetBeans IDE 7.0, click on the Services tab.
    2. Right-click on the JavaDB node, and then click on Create Database…
    3. Enter the database name, user name and password in the provided text boxes. Use “mydb” for the user name and password.
  4. Create a new connection to the newly-created database.
    1. On the “Services” tab, right-click on the “Databases” node, and then click on “New Connection…”
    2. We will use JavaDB Network for this tutorial, so select “JavaDB (Network)” for the driver. Then, click Next.
    3. Enter Host Name: localhost, Port: 1527, Database: CustDB, User name: mydb, and Password: mydb.
    4. Click Next
    5. Select “APP” as the schema name
    6. Click Finish
    7. A new connection node: jdbc:derby:localhost:1527/CustDB [myapp on APP]
  5. Create a new table in CustDB
    1. Expand the CustDB connection node
    2. Expand the APP node under CustDB node
    3. Right-click on the “Table” node under the CustDB/APP node, and click on “Execute Command…” to open an SQL window
    4. Copy the SQL script shown above into the SQL window, and click “Execute” icon.
  6. Create Java Library Project
    1. On the Netbeans IDE 7.0 menu, File –> New Project
    2. Categories: Java and Projects: Java Class Library
    3. Click Next
    4. Project Name: MyCustomerLibraryProject
    5. Click Finish
    6. On the Project tab, right-click on the MyCustomerLibraryProject node –> New –> Entity Classes from Databases …
    7. Select the CustDB connection that is just created above for the Database Connection. Then, there should be only one available table, named Customer.
    8. Click “Add All” and then click “Next”
    9. Put “demo” as the package name, and then click “Finish”
  7. Modify the generated Customer.class file in the MyCustomerJavaLibraryProject
    1. Click the “demo” node to expand the node, there will be one Java file named, “Customer.java”.
    2. Click the file to open it in the NetBeans IDE editor.
    3. Since we use “mydb” as user name and password, we need to use a fully-qualified name for the table name. So, change:

      @Table(name = "CUSTOMER")


      @Table(name = "APP.CUSTOMER")

      The reason is that JavaDB will presume that the user name, in this case “mydb”, is the schema name, however, we create the Customer table in “APP” schema. As a result, we need to use a fully-qualified name for the Customer table which is “APP.CUSTOMER”.

    4. In JavaDB, EclipseLink maps “BLOB” SQL data type into “Serializable” Java SQL data type. However, to store an image, we need to use “byte[]” Java SQL data type. Accordingly, we need to change:
      • The data type of “photo” variable definition from Serializable to byte[].

        @Column(name = "PHOTO")
        private Serializable photo;


        @Column(name = "PHOTO")
        private byte[] photo;
      • The returned data type of getPhoto() method from Serializable to byte[]

        public Serializable getPhoto() {
        return photo;


        public byte[] getPhoto() {
        return photo;
      • The parameter data type of setPhoto() from Serializable to byte[]

        public void setPhoto(Serializable photo) {
        this.photo = photo;


        public void setPhoto(byte[] photo) {
        this.photo = photo;

    5. Now, we are ready to generate MyCustomerLibrary.jar by right-clicking on the “MyCustomerLibraryProject” and then click “Clean and Build”
  8. Create a Library Wrapper module containing “MyCustomerLibraryProject.jar” created above. Then, set the dependencies of this module to DerbyClient and EclipseLink library wrapper modules. Assume that these two modules are created beforehand.
  9. Now, in a Java code where we need to save an image from JLabel into our CustDB database in JavaDB, use the following code snippet.

    //Store image from jLabel into JavaDB
    Customer newCustomer = new Customer();
    ImageIcon imgIcon = (ImageIcon) jLabelImage.getIcon();

    if (imgIcon != null) {

    Image img = imgIcon.getImage();
    byte[] imgByte = getByteArrayFromImage(img);


  10. The getByteArrayFromImage() method is defined as follows.

    private byte[] getByteArrayFromImage(Image img) {

    byte[] imgByte = null;

    try {
    int imgWidth = img.getWidth(null);
    int imgHeight = img.getHeight(null);
    int imgType = BufferedImage.TYPE_INT_ARGB; // you can experiment with this one
    BufferedImage bi = new BufferedImage(imgWidth, imgHeight, imgType);
    Graphics2D g2 = bi.createGraphics();
    g2.drawImage(img, 0, 0, null);

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    if (ImageIO.write(bi, "JPEG", baos)) {
    imgByte = baos.toByteArray();

    } catch (IOException ex) {

    return imgByte;


  11. In addition, for the Java code where an image is loaded from CustDB and displayed in JLabel, use the following code snippet:

    //For image from database to jLabel
    Customer existingCustomer = getCustomerFromDB(customerID);//load a Customer object from database
    byte[] imageByte = existingCustomer.getPhoto();
    if (imageByte != null) {

    ImageIcon imageIcon = new ImageIcon(imageByte);
    java.awt.Image img = imageIcon.getImage();



  12. That’s pretty much all we need to do. However, you may need to specify allowable image file types, and scale an image before putting in a JLabel.
  13. The methods in steps #9, #10 and #11 can be used for MySQL database. The thing is that MySQL maps BLOB SQL data type into byte[] Java SQL data type. Therefore, we do not need to do step #7.
  14. The most important steps are #7, #9, #10 and #11 that we need to modify Customer.java file and define save/load methods.

Have fun!

Posted in Uncategorized | 5 Comments