|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.exolab.castor.util.SqlBindParser
public final class SqlBindParser
Utility class to parse an SQL or OQL expression for bind variables Bind variables are subexpressions of the form "$n", where n is a positive integer number. To parse the expression, call SqlBindParser.next() in a loop until no more bind variable can be found. Each call moves on to the next bind variable and returns true if another could be found. Inside the loop call SqlBindParser.getBindExpr() to access the current bind variable expression. ("$1", "$2", ...) SqlBindParser.getParamNumber() can be used to read the parameter number (1, 2, ...). If you are interested in the remainder of the expression string, just call getLastExpr() to get the last processed substring. For example, when parsing the expression "select * from x where id between $1 and $2" this gives you the following function returns: next() -> true getLastExpr() -> "select * from x where id between " getBindExpr() -> "$1" getParamNumber() -> 1 next() -> true getLastExpr() -> " and " getBindExpr() -> "$2" getParamNumber() -> 2 next() -> false getLastExpr() -> ""
Constructor Summary | |
---|---|
SqlBindParser(java.lang.String sql)
Create a new SqlBindParser instance to parse the expression in 'sql'. |
Method Summary | |
---|---|
static void |
bindJdbcValues(java.sql.PreparedStatement stmt,
java.lang.String pre_sql,
java.lang.Object[] values)
Binds values to prepared SQL statement using the given sql string as reference for the bind variable order. |
java.lang.String |
getBindExpr()
Returns the current bind variable expression, e.g. |
static java.lang.String |
getJdbcSql(java.lang.String pre_sql)
Creates a SQL statement from pre_sql, replacing bind expressions like "?1" by "?" |
java.lang.String |
getLastExpr()
Returns the expression substring beginning after the last processed bind variable and ending just before the current bind variable. |
int |
getParamNumber()
Returns the parameter number of the current bind variable, for example 1 a "$1" bind variable. |
boolean |
next()
Move on to the next bind variable in '_sql'. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public SqlBindParser(java.lang.String sql)
sql
- expression to be parsedMethod Detail |
---|
public boolean next()
public java.lang.String getLastExpr()
public java.lang.String getBindExpr()
public int getParamNumber()
public static java.lang.String getJdbcSql(java.lang.String pre_sql)
pre_sql
- SQL statement string with bind variables of the form "?1"
public static void bindJdbcValues(java.sql.PreparedStatement stmt, java.lang.String pre_sql, java.lang.Object[] values) throws java.sql.SQLException
stmt
- JDBC statementpre_sql
- SQL statement string with bind variables of the form "?1"values
- array of bind values
java.sql.SQLException
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |