I have class object rand and it has got method getRn1() getRn2() up 10 so I am using loop but it is inserting name of method as string rather then value for(int i=1;i<11;i++){ String one="rand.getRn"+i+"()"; String two="rand.getOc"+i+"()"; System.out.println(one); System.out.println(two); if(one.equals("") | | two.equals("")){}else{ String si="INSERT INTO random " +"(random_no,outcomecode)"+ "VALUES(\'"+one+"\',\'"+two+"\')"; System.out.println(si); rows = myStatement.executeUpdate(si); System.out.println(rows);}} please help me kajal_sharma
prabhat kumar
Ranch Hand
Joined: Apr 11, 2001
Posts: 114
posted
0
Originally posted by kajal sharma: I have class object rand and it has got method getRn1() getRn2() up 10 so I am using loop but it is inserting name of method as string rather then value for(int i=1;i<11;i++){ String one="rand.getRn"+i+"()"; String two="rand.getOc"+i+"()"; System.out.println(one); System.out.println(two); if(one.equals("") | | two.equals("")){}else{ String si="INSERT INTO random " +"(random_no,outcomecode)"+ "VALUES(\'"+one+"\',\'"+two+"\')"; System.out.println(si); rows = myStatement.executeUpdate(si); System.out.println(rows);}} please help me kajal_sharma
ur code .. for(int i=1;i<11;i++){ String one="rand.getRn"+i+"()"; String two="rand.getOc"+i+"()"; what u r doing here is creating string objects ..u can't call functions as u inteded to .. what u do is make only one function ..rand.getRn(int i) and pass the parameter in the function definition u check for this parameter and return the appropriate values ..so instead of 10 methods u make only one methods and check for parameter ... then it will be like this ... for(int i=1;i<11;i++){ String one=rand.getRn(i); String two=rand.getOc(i); System.out.println(one); System.out.println(two); if(one.equals("") | | two.equals("")){}else{ String si="INSERT INTO random " +"(random_no,outcomecode)"+ "VALUES(\'"+one+"\',\'"+two+"\')"; System.out.println(si); rows = myStatement.executeUpdate(si); System.out.println(rows);}} hope this will help .. Prabhat kumar