Monday, May 25, 2015

Pagination in java jsp.

The pagination is very useful when we have large number of records in a table. If we displaying all the record the at a time it will take more time to load all the data and taking more memory. So it's not a good for either memory or performance point of view. If we go for pagination it will load limited amount of record at a time so it will good for both memory and performance point of view.

In this example i'm going to display one of db table record in tabular format using pagination. I'm loading only 5 record at a time. Each request fetching  only 5 Record at a time by using below variable-
showRows = 5 (display the number of record per page)
totalRecords = 5 display the number of page at a time like 1,2,3,4,5 hyper link will come on each time

Monday, May 11, 2015

How to write a XML file in java.

Step 1- Create document

Step 2- Create root element

Step 3- Append root into document

Step 4- Create child element of root element

How to read XML file in java.

We can read a xml by following stpes-

Step 1- Create File object of xml file.

1
fXmlFile = new File("src\\myXml.xml");

Step 2- Create a document and parse the xml and sotore it into document object

1
2
3
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(fXmlFile);

How to transfer ResultSet object over network in java.

As we know the ResultSet object can not be transfer over the network. So for transferring the ResultSet object we need to set this object in Custom object and send this custom object over the network.

Step 1- Create UserTest class

Step 2- Retrieve the ResultSet object and set it into custom object (UserTest)

Saturday, May 9, 2015

How to add two array in java.

Step 1- Create two array

1
2
String a0[] = { "A", "E", "I" };
String b0[] = { "O", "U" };

Step 2- Convert these arrays into List

1
2
List a1 = new ArrayList(Arrays.asList(a0));
List b1 = new ArrayList(Arrays.asList(b0));

How to get the column name of table dynamically in jdbc.

While displaying the table data in jdbc we have to get ResultSet object using ResultSet we are displaying the table data by using rs.getInt(1) or rs.getString(“name”) like this.

But, If we don’t know the column name or number of column in table  we can use ResultSetMetaData for this. Using ResultSetMetaData we can  get the number of column, type of column, name of column and so on.

How to sort the object based on Id and Name in Java

If we have the List, Map or any other collection object we sort by using calling Collections.sort() method directly. But if we have our custom object we have to do some extra to sort our custom object. Assume that we have one Person Object like below

class Person{
    int id;
    String name;

    Setter…
    Getter…
}

Serialize and Deserialize the object in java.

Serialization is a process of converting an object into a sequence of bytes which can be persisted to a disk or database or can be sent through streams. The reverse process of creating object from sequence of bytes is called deserialization.

In this process there are three steps
1-    Create java class by implementing the Serializable class.
2-    Create SerializeDemo class to write a java object into file.
3-    Create DeserializeDemo class to read the java object from file.

How to download a file from server in java

To download a file from server is very easy task just get the file name and path and set the file name into response header (Content-Disposition) .
response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + "\"");

How to upload a file at server and store path in database in java.

To upload a file at server and storing a path in database we have to use JavaJoom Api. Add "uploadbean.jar" in your application and follow below steps –

How to send SMS in java.

To send a sms in java is very similar to send email in java. At the place of mail server (smtp host) we need to give some third party (which are providing the sms service) smtp host.
Many number of SMS provider in the market we can choose any of them. Here in my below 2 example I have choose two sms provider

1-    ipipi.com
2-    vianett.com

First example is using ipipi.com and second one is vianett.com.

Friday, May 1, 2015

How to send the mail in Java.

Sending mail in java is very easy just follow the below stpes-


Step 1- Create a property with smtp host, smtp port. Here I’m going the send the mail using gmail so I’m using smtp host as smtp.gmail.com and port is 465.

How to send the attachment mail in java

Sending mail in java is very easy just follow the below stpes-