Different types of server

About MVC

MVC(Model,View ,Controller)


1).  Model: The model object knows about all the data that need to be displayed. It is model who is aware about all the operations that can be applied to transform that object. It only represents the data of an application. The model represents enterprise data and the business rules that govern access to and updates of this data. Model is not aware about the presentation data and how that data will be displayed to the browser. 


2). View : The view represents the presentation of the application. The view object refers to the model. It uses the query methods of the model to obtain the contents and renders it. The view is not dependent on the application logic. It remains same if there is any modification in the business logic. In other words, we can say that it is the responsibility of the of the view's to maintain the consistency in its presentation when the model changes.


3). Controller:  Whenever the user sends a request for something then it always go through the controller. The controller is responsible for intercepting the requests from view and passes it to the model for the appropriate action. After the action has been taken on the data, the controller is responsible for directing the appropriate view to the user. In  GUIs, the views and the controllers often work very closely together.

Different types of database


DB2                             DB2 AS/400                         DB2 OS390

PostgreSQL                 MySQL                                 Oracle

Sybase                         Microsoft SQL Server          SAP DB

Informix                      HypersonicSQL                    Ingres

Progress                      Mckoi SQL                           Interbase

Pointbase                    FrontBase                              Firebird

disabling table cell in java

Here when user enter value 3 for a cell in a table, then that cell becomes uneditable


class Testing
{
public void buildGUI()
{
JTable table = new JTable(5,3){
public boolean isCellEditable(int row,int column){
Object o = getValueAt(row,column);
if(o != null && o.equals("3")) return false;
return true;
}
};
JFrame f = new JFrame();
f.getContentPane().add(new JScrollPane(table));
f.pack();
f.setLocationRelativeTo(null);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
public static void main(String[] args)
{
SwingUtilities.invokeLater(new Runnable(){
public void run(){
new Testing().buildGUI();
}
});
}
}

Stored Procedure Names in a database using java

Retrieves the names of all stored procedures in a database.

try {
// Get database metadata
DatabaseMetaData dbmd = connection.getMetaData();

// Get all stored procedures
ResultSet resultSet = dbmd.getProcedures(null, null, "%");

// Get stored procedure names from the result set
while (resultSet.next()) {
String procName = resultSet.getString(3);
}

} catch (SQLException e) {
System.out.println(e);
}

Round double value using java

You can round a double using the setScale() method of BigDecimal class.

public double round(double d, int decimalPlace) {

BigDecimal bd = new BigDecimal(Double.toString(d));

bd = bd.setScale(decimalPlace, BigDecimal.ROUND_HALF_UP);

return bd.doubleValue();

}

java panel with background image in swing

Following code show how to display background image on a JPanel

public class ImageTest {
public static void main(String[] args) {
ImagePanel panel = new ImagePanel(new ImageIcon("images/img.png").getImage());
JFrame frame = new JFrame();
frame.getContentPane().add(panel);
frame.pack();
frame.setVisible(true);
}
}

class ImagePanel extends JPanel {

private Image img;

public ImagePanel(String img) {
this(new ImageIcon(img).getImage());
}

public ImagePanel(Image img) {
this.img = img;
Dimension size = new Dimension(img.getWidth(null), img.getHeight(null));
setPreferredSize(size);
setMinimumSize(size);
setMaximumSize(size);
setSize(size);
setLayout(null);
}

public void paintComponent(Graphics g) {
g.drawImage(img, 0, 0, null);
}

}

sorting vector contains vector elements

Sort java vector which contain another vector as its elements, here sorting is based on last element of the vector(element of main vecotor)

Vector result = new Vector();
Object[] o = result.toArray();

Arrays.sort(o, new Comparator() {

public int compare(Object o1, Object o2) {
Vector v1 = (Vector) o1;
Vector v2 = (Vector) o2;
Object[] res1 = v1.toArray();
Object[] res2 = v2.toArray();
int len = res1.length;
if (Double.parseDouble(res1[len - 1].toString()) == Double.parseDouble(res2[len - 1].toString())) {

return 0;
} else if (Double.parseDouble(res1[len - 1].toString()) > Double.parseDouble(res2[len - 1].toString())) {
return -1;
} else {
return 1;
}

}
});
// create new vector ie sorted vector
Vector new=new Vector(Arrays.asList(o));