Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Parameter

 
Jennifer Sohl
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do I pass the value from a parameter field (:NAME) to a String variable (newvend)? What is the syntax? Is it anything like newvend = :NAME? I can't seem to find any documentation on this. Please help.
A clueless newbie,
Thanks!
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you will need to give us a bit more context. Where does your parameter come from? what does it contain?
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the value is coming in as a parameter on a method, you can use the variable name that the method defined in the signature.
public void myMethod(String s){
System.out.println(s);
}
When the method is called with
String name = "Cindy";
myMethod(name);
The input parameter will be printed on the console.
If the parameter is coming in from the command line
>java myApp Cindy
Then in the main method you need to set the variable to the value of arg[0]
String x = arg[0];
System.out.println(x);
will print Cindy to the console.
 
Jennifer Sohl
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a SELECT statement:
"SELECT dbo.PCVENDX.PCVNO, dbo.PCVENDX.PCVNM, FROM dbo.PCVENDX WHERE ( ( dbo.PCVENDX.PCVNO = :NEXT ) )";
Whatever the user keys into the vendor number field, gets passed to the :NEXT parameter.
Now, I need to pass the value of the :NEXT parameter to a String variable name "newvend".
Could you do something like this:
newvend = getNextVendor.getParameter("NEXT") ??
Sorry, this is hard to explain. Let me know if I've confused you!
BTW, is there somewhere that I could find examples or documentation on syntax when parameter fields(from a SELECT statement) are involved?
Thanks for your time!
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

TextField vendorNumber = new TextField(10);
String next = vendorNumber.getText();
String sql = "SELECT dbo.PCVENDX.PCVNO, dbo.PCVENDX.PCVNM, FROM dbo.PCVENDX WHERE ( ( dbo.PCVENDX.PCVNO = " + next + " ) )";
Then use the sql variable to make your JDBC call.
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can also use PreparedStatemens. Find out more here: http://java.sun.com/j2se/1.3/docs/api/java/sql/PreparedStatement.html
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic