getting all the data from mysql database table is not working in java -


i trying data table.but it's giving me first row twice result (as have 2 rows in database)

here code

   string data[]=new string[10];      string[] result;      product p= new product();      int serial=0;        try{             string sql="select * product";             rslt=st.executequery(sql);  //where private static statement st, private static resultset rslt;             while(rslt.next()){                 data[1]=rslt.getstring("p_code");                 data[2]=rslt.getstring("p_name");                /* data[3]=rslt.getstring("description");                   data[4]=rslt.getstring("measurement");                   data[5]=integer.tostring(p.remainproduct(data[1]));                   data[6]=p.getsellprice(data[1]);                   serial+=1;                   data[0]=integer.tostring(serial);                   dtb.addrow(data); */                   system.out.println("code :"+data[1]+" "+"name :"+data[2]);               }       }catch(exception ex){          system.out.println("error :"+ex);       }  

my table has 2 data, here database table data

enter image description here

and here result after run program.

enter image description here

i don't know actual problem. same code works fine on other method why can't here. new java, please me fixing problem

your code looks correct me. think case of "what looking @ not broken". perhaps not querying table think querying, or perhaps table view cached , out of date. refresh table view, , try printing out pk (id column in table) in program output double check table querying correct table. also, double check jdbc url , verify querying correct database.

also, comments indicate same code giving correct results in different method. maybe there more going on in actual code don't have insight into? perhaps code (not shown in example) is:

  1. updating table row 1 , 2 have same data.
  2. querying database (as shown in example), , returning same data in row 1 , 2.
  3. update table row 1 , 2 have different data shows when manually query database.

finally, make sure of other team members or automated test process isn't updating table without knowledge.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -