Tuesday, 15 March 2011

Java Array Of Record Solution -


Text after "div class =" itemprop = "text">

I rewrite an Informix-4 GL program in Java and I'm having some problems with data retrieving from the database Is busy

I am currently using SQLite3 for testing purposes and I am compiling and executing my code from Windows Command Line (not using any IDE at this point).

The problem is I am being used to use the Informix-4GL dynamic array of such records as below:

  records DataArray dynamic array of data_id integer, data_name four (15), data_desc four (15) end record  

which I am able to populate as please and then

  retrieves data using the displayed data array [3] (example third line inserted) .data_id < / Code> 

I would like to know the recommended way to create some simulators in Java, is it possible to store Java's equivalent data of the dynamic array of records and then select the data identifier Using some form of?

Here's how I did this in Informix-4GL. It's more clear

  main lv_string string, # normal variable lv_cnt integer, define lr_table record like table . *, To create the DataArray dynamic record array, # value I am storing in array data_id integer, data_name four (15), data_desc four (15) end record lv_string = "selection from table *", let's # statement statement 01 " Where 1 = 1 "data_curs declare the data_prep from the lv_string, give the cursor to the data_prep, select from lv_string =" table = 02 ", # create statement 01" id =? " In lr_table, lv_cnt = 0 foreach data_curs let's create data02_prep from lv_string. * Go to loop # through the SQL return results lv_cnt = lv_cnt + 1 dataArray [lv_cnt] .data_id = lr_table.id # Go to the store variable go to DataArray [lv_cnt] .data_name = lr_table. Use execution data02_prep data ranging from data to lr_table.id # store variablesAre [lv_cnt] .data_desc # different table end foreach if dataArray.getLength () = 5 then uses the # data that I have displayed "here are 5 rows Finally, if dataArray.getLength () = 17 then # is very flexible performance dataArray [5] .data_id, dataArray [9] .data_name dataArray [14] .data_desc if the main  

This is not the end of the actual program, but I only take those features which I would like to recreate in Java.

The best part about this is that I can ask the database once and close the connection, I will not need it. Or again ask the database for the entire duration of the program.

I think in your case, an ArrayList is very easy Example

  public class sample {list & lt; Data & gt; Datas = new arreelist & lt; Data & gt; (); Datas.add (new data ("1", "2", "3")); Datas.add (new data ("4", "5", "6")); Datas.get (0); // You must first give data} class data {object ID, name, character; Data (object ID, object name, object dis) {this.id = id; This.name = name; This.desc = desc; By the way, I think that you have problems with Hashmap (which you say is overridden) because you do not override the same and hashed method because these Two methods are used to keep the object in the hashmap.  

Hope this is your help: D

===============

Assume that your line The variable is referring to ResultSet, so you can do this. Public zero doFill {result row} {while (row.next ()) {datas.add (new data (line .getObject ("id"), line .get object ("name "), Line .get object (" desc "))); }}


No comments:

Post a Comment