Guide to MySQL database Engine.

A MySQL database gives you a choice of database engines and an easy way to switch them.

Default MySQL Engine would be enough for most of your application but in certain circumstances where the other available engines may be better suited to the task at hand.

Choose your engine
The number of database engines available to you depends on how your installation of MySQL was compiled. To add a new engine, MySQL must be recompiled. The concept of compiling an application just to add a feature may seem odd to Windows developers, but in the UNIX world, it’s the norm. By default, MySQL supports three database engines: ISAM, MyISAM, and HEAP. Two other types, InnoDB and Berkley (BDB), are often available as well.

ISAM
ISAM is a well-defined, time-tested method of managing data tables, designed with the idea that a database will be queried far more often than it will be updated. As a result, ISAM performs very fast read operations and is very easy on memory and storage resources. The two main downsides of ISAM are that it doesn’t support transactions and isn’t fault-tolerant: If your hard drive crashes, the data files will not be recoverable. If you’re using ISAM in a mission-critical application, you’ll want to have a provision for constantly backing up all your live data, something MySQL supports through its capable replication features.


MyISAM

MyISAM is MySQL’s extended ISAM format and default database engine. In addition to providing a number of indexing and field management functions not available in ISAM, MyISAM uses a table-locking mechanism to optimize multiple simultaneous reads and writes. The trade-off is that you need to run the OPTIMIZE TABLE command from time to time to recover space wasted by the update algorithms. MyISAM also has a few useful extensions such as the MyISAMChk utility to repair database files and the MyISAMPack utility for recovering wasted space.

MyISAM, with its emphasis on speedy read operations, is probably the major reason MySQL is so popular for Web development, where the vast majority of the data operations you’ll be carrying out are read operations. As a result, most hosting and Internet Presence Provider (IPP) companies will allow the use of only the MyISAM format.

HEAP
HEAP allows for temporary tables that reside only in memory. Residing in memory makes HEAP faster than ISAM or MyISAM, but the data it manages is volatile and will be lost if it’s not saved prior to shutdown. HEAP also doesn’t waste as much space when rows are deleted. HEAP tables are very useful in situations where you might use a nested SELECT statement to select and manipulate data. Just remember to destroy the table after you’re done with it. Let me repeat that: Don’t forget to destroy the table after you’re done with it.

InnoDB and Berkley DB
The InnoDB and Berkley DB (BDB) database engines are direct products of the technology that makes MySQL so flexible, the MySQL++ API. Almost every challenge you’re likely to face when using MySQL stems directly from the fact that the ISAM and MyISAM database engines aren’t transactional and lack foreign-key support. Although much slower than the ISAM and MyISAM engines, InnoDB and BDB include the transactional and foreign-key support missing from the former two choices. As such, if your design requires either or both of these features, you’re actually compelled to use one of these two choices.

If you’re feeling particularly capable, you can create your own database engine using MySQL++. The API provides all the functions you need for working with fields, records, tables, databases, connections, security accounts, and all of the other myriad functions that make up a DBMS such as MySQL. Going too heavily into the API is beyond the scope of this article, but it’s important to know that MySQL++ exists and that it’s the technology behind MySQL’s swappable engines. Presumably, this model of plug-in database engines could even be used to build a native XML provider for MySQL. (Any MySQL++ developers reading this may consider that a request.)

Permanent link to this article: https://blog.openshell.in/2011/06/guide-to-mysql-database-engine/

CSS – Rounded Corner with shadow

Target Audience : Web Developers

Hello, web developers!

Here I would like to tell you how to make the round corner with shadow for banners or any other components of html.

Look the code below:

-moz-border-radius-bottomright: 14px;
-moz-border-radius-bottomleft: 14px;
-web-border-radius-bottomright: 14px;
-web-border-radius-bottomleft: 14px;
-webkit-border-radius-bottomright: 14px;
-webkit-border-radius-bottomleft: 14px;
border-bottom-right-radius: 14px;
border-bottom-left-radius: 14px;
-moz-box-shadow: 0 0 25px #6C6C6C;
-webkit-box-shadow: 0 0 25px #6C6C6C;
box-shadow: 0 0 25px #6C6C6C;

For Example, if i am going to apply it for an image, then i should have the above code in my css as,

#img{
    -moz-border-radius-bottomright: 14px;
    -moz-border-radius-bottomleft: 14px;
    -web-border-radius-bottomright: 14px;
    -web-border-radius-bottomleft: 14px;
    -webkit-border-radius-bottomright: 14px;
    -webkit-border-radius-bottomleft: 14px;
    border-bottom-right-radius: 14px;
    border-bottom-left-radius: 14px;
    -moz-box-shadow: 0 0 25px #6C6C6C;
    -webkit-box-shadow: 0 0 25px #6C6C6C;
    box-shadow: 0 0 25px #6C6C6C;
}

Now in html,

<html>

<head>

<title>Rounded Corner with shadow</title>

</head>

<body>

<img id=”img” src=”banner.jpg” alt=”banner” width=”500px” height=”200px”/>

</body>

</html>

And run the html, You will get a banner which will have rounded corner with shadow…

Try it and enjoy……

Permanent link to this article: https://blog.openshell.in/2011/05/css-rounded-corner-with-shadow/

Java Essential Tips: Display JFrame in Center of the Screen

Target Audience: Java Beginners, Java Swing Developers

What should you know already? Basics of Java Swing

The beginners of Java might query “How do I display JFrame in center of screen?” on Google quite frequently. JFrame is the top level container in Swing API to show your GUI application.

Commonly, there are 2 methods available for setting location to any subclass of Component. They are:

  • setLocation(int x, int y)
  • setLocationRelativeTo(Component parent)

The first method accepts 2 integer values as X and Y co-ordinates on the screen. So, if you use this method, your JFrame would appear at the specific location.

The second method needs a Component. It sets the location of your JFrame relative to this component. If the component is not showing or it is null, then JFrame would be placed in center of the screen.

Look at the following source code for centering JFrame on the screen:

import javax.swing.JFrame;
import javax.swing.JLabel;
public class DemoTopLevel {
    public DemoTopLevel() {
        JFrame frame=new JFrame("Demo");
        JLabel lbl=new JLabel("Hello World! Exploring Java Swing API!!!");
        frame.getContentPane().add(lbl);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }
    public static void main(String [] arguments){
        new DemoTopLevel();
    }
}

Note: The setLocationRelativeTo(null); code must be after calling pack() or setSize() method. Otherwise it would set the location first then changes its width and height, which is actually not visible at center of the screen.

Feel free to send comments. About Author

Similar Posts

Permanent link to this article: https://blog.openshell.in/2011/05/java-essential-tip-display-jframe-in-center-of-the-screen/

Java Essestial Tips: ArrayIndexOutOfBoundsException when Delete Elements From JList

Target Audience: Java Beginners, Java UI Developers, Swing Developers

What should you know already? Java Swing API

When you work around Java Swing UI components, especially JList, JTable or JComboBox, you should give your attention more than the attention you are giving for other components. Because these components are not just a single control, it has 0 or more elements in it. So, adding or deleting elements should be done in a meaningful way.

This blog gives you a very useful tip about delete elements from JList which has multiple selection mode. First look at the following code, the typical way how elements can be added using DefaultListModel:

String fruits[]={"Grapes","Guaua","Pine Apple","Mango","Strawberry","Banana",
                      "Watermelon","Apple","Lemon","Muskmelon","Orange"};
final JList lstFruits=new JList();
final DefaultListModel listModel=new DefaultListModel();
for(String fruit:fruits)
     listModel.addElement(fruit);
lstFruits.setModel(listModel);
lstFruits.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);

lstFruits list contains 11 fruits. And create a JButton and bind ActionEvent for writing delete elements logic, as look as following code:

JButton btnDelete=new JButton("Delete");
btnDelete.addActionListener(
        new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                int [] selectedIndices=lstFruits.getSelectedIndices();
                    for(int index:selectedIndices)
                        listModel.removeElementAt(index);
              }
         }
 );

Now, create objects for JFrame and JPanel. Add lstFruits and btnDelete to JPanel object. Execute the code. Select single element and press Delete button. The selected element would be deleted. It works fine. However, select multiple elements of the list box (not essestially as sequence elements, select multiple interval selection) and press on Delete button. Now you could notice not all of the selected elements would be deleted. Don’t forget to check your console output for the exception thrown which might be likely as follows:


Exception in thread “AWT-EventQueue-0” java.lang.ArrayIndexOutOfBoundsException: 9 >= 6
   at java.util.Vector.removeElementAt(Vector.java:511)
   at javax.swing.DefaultListModel.removeElementAt(DefaultListModel.java:312)

What is the reason?

You could come to know the reason for this exception if you analyze the delete logic. We are deleting the selected elements using a loop. So it deletes one element in one iteration. Note, when it deletes an element from the list, Java updates the index of existing elements in the list. So, in the next iteration, if you are trying to delete an element by its selected index, the element might not be available at the selected index, since Java had updated the index values in the last iteration. So, its position within the list is changed.

How to solve?

Delete the element, whose index is biggest, first. If you follow this tip, no chance for the exception. The trick is start iteration in reverse order. Check the following code:

btnDelete.addActionListener(
        new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                int [] selectedIndices=lstFruits.getSelectedIndices();
                int length=selectedIndices.length;
                for (int index = length - 1; index >= 0; index--)
                       listModel.removeElementAt(selectedIndices[index]);
              }
         }
 );

The above logic neatly deletes the selected elements from JList without any exceptions. You can use the same kind of trick for JTable also.

Feel free to send comments. About Author

Similar Posts

Permanent link to this article: https://blog.openshell.in/2011/05/java-essestial-tips-arrayindexoutofboundsexception-when-delete-elements-from-jlist/

Excel to MySQL using Java

Target Audience: Java Developers, Database Developers
What should you know already? Basics of Java, JDBC

Excel to MySQL conversion can be done using LOAD DATA INFILE command as I discussed in Excel to MySQL blog. But that command is inadequate when you need to read the excel cell value and making some calculations or concatenations with it, then insert into your relational table. In this situation we need to read excel worksheet using programming languages and do the process before insert. Lets discuss this with Java.

Apache POI API

POI is a project from Apache to create Java API for manipulating various file formats based upon the Office Open XML standards (OOXML) and Microsoft’s OLE 2 Compound Document format (OLE2), simply talking, to read and write MS Excel files using Java. Check the references for POI API documentation.

Reading – Writing Excel

Horrible SpreadSheet Format (HSSF) API is for reading/writting Excel files using pure Java. Check the following list of classes from this API, which are needed to access excel file:

  • org.apache.poi.hssf.usermodel.HSSFCell
  • org.apache.poi.hssf.usermodel.HSSFRow
  • org.apache.poi.hssf.usermodel.HSSFSheet
  • org.apache.poi.hssf.usermodel.HSSFWorkbook
  • org.apache.poi.poifs.filesystem.POIFSFileSystem

Of above, POIFSFileSystem class is used to initiate the underlying operating system’s file structure. It requires an object of java.io.InputStream. An object of type POIFSFileSystem is given to HSSFWorkbook in order to retrieve the workbook. The following code snippet illustrates this:

File excelFile=new File(“location-of-excel-file/filename.xls”);
FileInputStream inStream=new FileInputStream(excelFile);
POIFSFileSystem fileSystem=new POIFSFileSystem(inStream);
HSSFWorkbook workBook = new HSSFWorkbook (fileSystem);

Once you create object for HSSFWorkbook, then you can access a work sheet by providing work sheet index number or its name (say sheet1). Suppose you want access very first work sheet, then the code would be:

/** getting sheet by its index number */
HSSFSheet workSheet=workBook.getSheetAt(0);

(or)

/** getting sheet by its name */
HSSFSheet workSheet=workBook.getSheet(“sheet1”);

The next step is to access rows and cells of each row. A work sheet consists of many rows but not all rows has content. A row has many cells. To simplify the access of rows and cells, we need to use java.util.Iterator with generic type reference HSSFRow and for accessing cells in a row, use another Iterator with generic type reference HSSFCell. Once you access a cell, you can read its content, style, cell number, etc. A cell may contain numerical value or alpha-numerics or booleans. The HSSFCell class has certain methods to check this. Look at the following code snippet:

Iterator rows=workSheet.rowIterator();
Iterator cells=null;
HSSFRow aRow=null;
HSSFCell aCell=null;
while(rows.hasNext()){
    aRow=rows.next();
    cells=aRow.cellIterator();
    while(cells.hasNext()){
      aCell=cells.next();
      switch(aCell.getCellType()){
        case HSSFCell.CELL_TYPE_NUMERIC:
          System.out.println(aCell.getStringCellValue());
          break;
        case HSSFCell.CELL_TYPE_STRING:
          System.out.println(aCell.getNumericCellValue());
          break;
      }
      }
    }
}

Once you could access the cell values like the above code, then there would be no problem for constructing insert query you require for your application. Use JDBC API to insert the calculated values of excel sheet row into your relational table.

References

Permanent link to this article: https://blog.openshell.in/2011/05/excel-to-mysql-using-java/

Clearing Floats with Overflow using CSS

One of the common problems we face when coding with float based layouts is that the wrapper container doesn’t expand to the height of the child floating elements. The typical solution to fix this is by adding an element with clear float after the floating elements or adding a clearfix to the wrapper. But did you know you can also use the overflow property to fix this problem? It’s not a new CSS trick either.

The above image shows the issue with floating child elements where the parent container doesn’t expand. To fix this problem, you can simply add the CSS property overflow:auto (or overflow:hidden) to the wrapper container. This is perhaps the simplest way to clear floats.

.container {
overflow: auto;
}

Overflow:auto can also be used to prevent content from wrapping around the floated element. Let’s say you are designing a comment list. You would, most likely, have an avatar floating on the left and the comment to the right. To prevent the comment from wrapping around the avatar just add overflow:hidden to the comment container. The advantage of using overflow here is that I don’t have to set a float or width to the comment container. The container automatically aligns after the floated avatar image.

.image {
float: left;

.text {
overflow: hidden;
}

Drawbacks:
Although it is a nice trick to clear floats there are some drawbacks:

Using overflow:auto will cause a scrollbar if your content is extending the boundary of the container. For example, if you have a long unbreaking text (ie. long url text) or a large image that is bigger then the container a scrollbar will show.
To avoid a scrollbar from showing you should use overflow:hidden. Again, there is a drawback to this method as well. Using overflow:hidden will hide any content that exceeds the boundry of the container.

Word-wrap
To solve the long unbreaking text issue, simply add word-wrap:break-word to the container and it will force the text to wrap onto a new line.

.container img {
max-width: 100%;
height: auto;
}

Max-width
To prevent large images from extending the boundar, add max-width:100% and it will resize the image to the max width of the container.

.container {
word-wrap: break-word;
}

Permanent link to this article: https://blog.openshell.in/2011/05/clearing-floats-with-overflow-using-css/

Ubuntu 11.04 – Available for download April 28, 2011 onwards.

Canonical announced the release of Ubuntu a fast-growing open-source operating system on April 28, 2011 for public download. Ubuntu 11.04 stands out from its competitors as a genuine free alternative to Windows, allowing users to personalise their PC with free and paid apps in a way that’s proven hugely popular in the smartphone and tablet market.

Ubuntu 11.04 introduces Unity interface, which is meant to be easier to use and more beautiful than previous editions. This version incorporates graphics that is inspired by smartphone and tablet design thinking.
ubuntu 11.04

Users who install Ubuntu 11.04 will find a clean workspace with a launcher on the left hand side of the screen.

The same interface can be used on a netbook, notebook or desktop PC. Ubuntu 11.04 will support Touch screens are fully supported in Ubuntu 11.04

In addition, Ubuntu is the first operating system support the Rupee Symbol, which has recently been approved by the India government to be used in PC.

Permanent link to this article: https://blog.openshell.in/2011/04/ubuntu-11-04-available-for-download-april-28-2011-onwards/

Difference between $this and self?

Inside a class definition, $this refers to the current object, while self refers to the current class.

It is necessary to refer to a class element using self, and refer to an object element using $this.

self::STAT // refer to a constant like this
self::$stat // static variable
$this->stat // refer to an object variable like this

Permanent link to this article: https://blog.openshell.in/2011/04/difference-between-this-and-self/

What is the difference between padding and margins?

Margins and padding can be confusing to the web designer. After all, in some ways, they seem like the same thing white space around an image or object.

Padding is the space inside the border between the border and the actual image or cell contents. In the image, the padding is the yellow area around the contents. Note that padding goes completely around the contents: there is padding on the top, bottom, right and left sides.

Margins are the spaces outside the border, between the border and the other elements next to this object. In the image, the margin is the red area outside the entire object. Note that, like the padding, the margin goes completely around the contents: there are margins on the top, bottom, right, and left sides.

Permanent link to this article: https://blog.openshell.in/2011/04/what-is-the-difference-between-padding-and-margins/

Double and Triple equals operator in PHP

Have you been given a piece of code to maintain that has single, double and triple equal operators in it? What’s the difference?

Single Equals
A single equal sign in PHP is an assignment operator. It assigns the value of the right side to the variable on the left side.

For example:
$name = “jon”;
echo $name; //output is “jon”

Double Equals
Two equal signs in PHP is a comparison operator used to check if the value on the left is the same as the value on the right. This is what you normally use in If statements.

For example:
$a = 5;
$b = 4+1;
// then $a == $b is true

Triple Equals
Three equal signs in PHP is also a comparison operator but looks not only at the value but also looks at the type of the variables.

For example:
$age1 = “5”;
$age2 = 5;
// then $age1 == $age2 is true
// and $age1 === $age2 is false because the variables are of different types

Permanent link to this article: https://blog.openshell.in/2011/04/double-and-triple-equals-operator-in-php/