Monthly Archives: December 2013

Exporting Java DefaultTableModel To Excel Example


DefaultTableModel is one of swing JTable component. This DefaultTableModel class populate JTable data. In other words, JTable data (rows, columns, cells) is a DefaultTableModel instance / object.

However, this post example will show how to populate DefaultTableModel’s column headers, rows, and cells value only. So this example will not showing JTable presentation. FYI, building JTable is pretty easy.
Also DefaultTableModel can be used for storing any kind of tabular data for application purposes without need to presentate its data to JTable.
This post intended to show example for exporting data to excel from DefaultTableModel object.

The library that can build an excel file is ‘Apache POI’. You need to download it through this link
The title of this component is ‘the Java API for Microsoft Documents’. I think this title is quite self explanatory. In short, you can write & read MS Documents, including Excel using this component.

The Example

Continue reading

Easy Work With File Stream Processing Using Custom Java Class To Store & Retrieve File


Oftentimes, application needs to store documents i.e files or images on database record or file copy under specific folder.

Developers use Streaming class i.e OutputStream, InputStream, FileOutputStream, FileInputStream, BufferedOutputStream, BufferedInputStream.
Count of code’s line is a kind of lot. Although there are good examples spread out in a web, sometimes java beginners might get confused.

So, I made custom java class to make file stream processing simple. I call the class with ‘FileStreamProc’. This class can stored documents to database or file via ftp or copy method. Also retrieving documents from data source.
We don’t have to bother anymore about those streaming classes above when we use FileStreamProc class. However, those classes are inside FileStreamProc off course. Main functions of FileStreamProc are Upload, Download, and Delete for storing, retrieving and deleting respectively.
We only have to write 2 lines of codes to store a file to database.
In example of FileStreamProc usage:

FileStreamProc fp = new FileStreamProc("doc1");
fp.Upload("D:\\folder\\SOP.pdf", ProcessMethod.Database);

‘doc1’ refers to document ID value. ‘D:\folder\SOP.pdf’ is file path value. Pretty simple right ?
Continue reading