Populate a table by using Single pattern in Java -


I have created singleton design pattern in my Java program

  private entity owner; Private string owner name; Private string owner; Private string owner address; Private Ent Chartel; Private string owner email; Private string owner; Private stable owner ing example = new owner ML (); // coosntructor to make private so that this class can not be personalized Private OwnerML () {} // Find the only public available public stable owner GetInstance () {return example; } Public int getOwnerId () {Return OwnerId; } Public Zero Set OwnID (Int Owner ID) {this.OwnerId = OwnId; }  

I have used a different method to call the visual method

  public AERLIT & lt; Owner MLA & gt; SelectNonData () {Aare list and lieutenant; Owner MLA & gt; Owner List = New Arrestist & lt; Owner ML & gt; (); Try {Connection Con = DB.connect (); String selectQ = "choose from owners"; Prepared place PS2 = con.prepareStatement (selectQ); Results set rs = ps2.executeQuery (); While (rsnext ()) {Owner MLL owner Data = OwnML.getInstance (); Owndata.setOwnerId (rs.getInt (1)); Owndata.setOwnerName (rs.getString (2)); Owndata.setOwnerNic (rs.getString (3)); Owndata.setOwnerAddress (rs.getString (4)); Owndata.setOwnerTele (rs.getInt (5)); Owndata.setOwnerEmail (rs.getString (6)); OwnerList.add (OwnerData); } Rs.close (); Ps2.close (); Con.close ();  

Using the following method, I'm calling it in my interface

  ArrayList & lt; OwnML & gt; OwnerList = New Owner (CL). Selector Data (); Object oz [] [] = new object [owner list. ()] [6]; Int x = 0; For (Owner MT: Owner List) {obj [x] [0] = TGOOONID (); Obj [x] [1] = t.getOwnerName (); Obj [x] [2] = t.getOwnerNic (); Obj [x] [3] = t.getOwnerAddress (); Obj [x] [4] = t.getOwnerTele (); Obj [x] [5] = t.getOwnerEmail (); X ++; } "", "Tele", "Email", "Date", "Email", "Date", "Name", "Name", "NEC", "Email", "Vehicle ID", "Type", "Model" , "Year", "regender"}););  

The problem I am facing at this time is that it always repeats the data in the previous row if someone with me I can be very grateful if you can help.

There is a mayor blame in your design. That for owner ML square data R is considered

Every time you call OwnerML.getInstance () , the result shows the result in the OwnerList list, As a result, you can always keep a list with multiple references of the same object (singleton).

You can use singleton To be used as a data container should be forgotten (it is called Data Transfer Object (DTO). In fact, singletons are rarely useful for some (especially the exceptions: logging subsystems, operators of single hardware processing, and maybe spring-ish bean factory).

In short: OwnerML the constructor public and then change OwnML owner = data = OwnerML.getInstance (); Online with OwnML owner = data owner = new owner

>

=== edit ===

@ Anton Anton's comment was first, and it was correct I should type faster next time :)


Comments

Popular posts from this blog

Member with no value in F# -

java - Joda Time Interval Not returning what I expect -

c# - Showing a SelectedItem's Property -