• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

How to take method name in sql string

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
All that thinking. Doesn't it hurt? What do you think about this tiny ad?
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic