Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to take method name in sql string

 
kajal sharma
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic