views:

61

answers:

2

I want to store the Arraylist values into database(postgresql database) in java.

ArrayList<String> ActiveProcess = new ArrayList<String>();
        ArrayList<String> InActiveProcess = new ArrayList<String>();

I want to store the details in a database ProcessInfo table with following fields Process Name, Process Status, Email Sent, SMS Sent, LastModifiedTime. The ActiveProcess contains the process names are server.exe, Receiver.exe .etc its process status is true,Email Sent, SMS Sent is false.

The InActiveProcess contains the process names are SmsReceiver.exe, sender.exe .etc its process status is false ,Email Sent, SMS Sent is true .

How to do this..? Thank in advance.

+1  A: 

The best way is to keep it simple and avoid unnormal database design. So I would suggest a new table with two column (id, value) referenced by the main table using id

nanda
+2  A: 

build model class to facilitates storing process information in DB:

public class Process {
  public static enum TYPE { ACTIVE , NOT_ACTIVE } ; 

  private ArrayList<String> names ;
  private String emailSent emailSent ;
  private Date lastModification ;
  private Boolean status ;
  private TYPE type ;

  //
  // provide constructors + setter + getter methods
  //

}

to store process in DB , use:

public void saveProcess (Process p) {
  ArrayList<String> name = p.getProcessesName();  // or you can get iterator from the arraylist
  String emailSent = p.getEmailSent();
  Date lastModification = p.getLastModification();
  Boolean status = p.getStatus();

  //
  // use SQL insert statements to save info
  //

}

to get all processes:

public ArrayList<Process> getAllProcesses () {
  ArrayList<Process> processes = new ArrayList<Process>();

  //
  // use SQL select statement to get processes
  //

   return proceses ;
}

or you can pass TYPE to the method to get the active or non active processes.

Wajdy Essam