Home
Bind VariablesBind Variables
Bind variables allow you to place "markers" inside the SQL statement that will then be replaced at execution time with the values supplied. To this end JoSQL supports 2 flavours of bind variables:
  • Anonymous
    Anonymous bind variables are specified in the SQL by a ?. This is like JDBC bind variables. (JoSQL assigns anonymous bind variables a "real" name)
  • Named
    A named bind variable is any combination of letters or numbers, prefixed by : (i.e. like Oracle bind variables), examples are: :name, :myvar.
You specify your bind variables to JoSQL by using:
  • Query.setVariable (int, Object) method, for anonymous variables passing the index of the anonymous variable, anonymous variables start at index 1. For example: q.setVariable (4, myObj) will set the the value of the fourth ? in the statement to the object myObj.
  • Query.setVariable (String, Object) method, for named variables, the first arg specifies the name of the variable. For example: q.setVariable (":name", myObj) will set the value of the name bind variable to the object myObj. It doesn't matter if you provide the : prefix or not.
See Also