How do i increase performance of Java Desktop application dbase con...

Hi :

I am currently working with desktop application , is there any way to capture the data from the database and store it temporarily and use it wherever necessary in the Desktop application.

I mean something that works similar to cache or session in the web application , i need a solution for desktop application.

Thanks in Advance,

# Solution 1

Hi joanesilviyaj,

  I have attached a snip code that function closely to web session.
It uses hashtable to store data. And you can save the hashtable to
a text file before the application exit and read it again when the
application start.

CODE Snippet :

import java.util.*;

import java.beans.*;
class AppSession
// save session to a file
static public Hashtable<String, String> getSession(String file) throws Exception
FileInputStream fstream = new FileInputStream(file);
// Get the object of DataInputStream
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
StringBuffer sb = new StringBuffer();
String strLine = null;
//Read File Line By Line
while ((strLine = br.readLine()) != null)
//Close the input stream
// decode to hashtable
ByteArrayInputStream bis = new ByteArrayInputStream(sb.toString().getBytes());
XMLDecoder decoder = new XMLDecoder(bis);
Hashtable<String, String> session = (Hashtable<String, String>)decoder.readObject();
return session;
// read session from a file
static public void setSession(Hashtable<String, String> session, String fileName) throws Exception
// encode to xml
ByteArrayOutputStream bos = new ByteArrayOutputStream();
XMLEncoder encoder = new XMLEncoder(bos);
String encode = new String(bos.toByteArray());
// ensure parent directory exist
File file = new File(fileName);
String parentPath = file.getParent();
if( parentPath!=null )
File fileParent = new File(parentPath);
// create file
FileWriter fstream = new FileWriter(fileName);
BufferedWriter out = new BufferedWriter(fstream);
static public void main(String arg[]) throws Exception
Hashtable<String, String> session = new Hashtable<String, String>();

// for debugging: before
// save session
setSession(session, "c:/session.txt");
// read session
session = getSession("c:/session.txt");

// for debugging: after


# Solution 2


A message has been sent to some of our more experienced experts asking them to review your question. We will check back again to see if you are getting the help you need.

This request included Experts from Open Source Programming, Database, Windows Programming, Programming Languages.

Please do not respond to this comment; we will be monitoring your question for activity from the Experts.

Thank you for using Experts Exchange,

Moderator, Experts Exchange

# Solution 3

Use a cache, such as ehcache for maintaining a local copy.

# Solution 4

Are you maintaining the connection?  Or using a connection pool?

Maybe it's not required


PS:  If you want and need a cache, objects has pointed you to one of the best ;-)

# Solution 5

Hello bluebelldiscovery:

Thanks for the reply.Let me work on this code and see is that works for my Java desktop Applicaiton.

Thanks a lot for taking a step to reply me...!!!!!!!


# Solution 6

Hi Silviya

You are welcome. Let me know if you have any doubt.