Package com.jalios.util
Class SQLQueryResult
- java.lang.Object
-
- com.jalios.util.SQLQueryResult
-
public class SQLQueryResult extends java.lang.Object
This class performs a SQL (SELECT) query and provides access to the result set.Warning : This class does not check tables, fields, columns and where clause parameter against SQL injection. Make sure to only use validated parameter values, i.e. do not use values entered by end user, but only values coming from configuration files or authorized administrators.
- Since:
- jcms-5.5.0
- Version:
- $Revision: 121495 $
- Author:
- Olivier Dedieu
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
SQLQueryResult.Row
This class represents a row.
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.String[]
columnNames
protected int
errorCode
protected java.lang.String
errorMessage
protected boolean
isError
static java.lang.String
REVISION
protected java.util.List
rowList
protected java.lang.String
sqlQuery
protected java.lang.String
sqlState
-
Constructor Summary
Constructors Constructor Description SQLQueryResult(java.lang.String dataSource, java.lang.String sqlQuery, int maxRows)
Constructs a new SQLQueryResult.SQLQueryResult(java.lang.String dataSource, java.lang.String sqlQuery, java.lang.Object[] params, int maxRows)
Constructs a new SQLQueryResult.SQLQueryResult(java.lang.String dataSource, java.lang.String select, java.lang.String from, java.lang.String orderby, java.lang.String[] whereParams, java.lang.String[] whereValues, boolean and, int maxRows)
Constructs a new SQLQueryResult.SQLQueryResult(java.sql.Connection conn, java.lang.String sqlQuery, java.lang.Object[] params, int maxRows)
Constructs a new SQLQueryResult.SQLQueryResult(java.sql.ResultSet rs)
Constructs a new SQLQueryResult.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
getColumnCount()
Returns the column countjava.lang.String[]
getColumnNames()
Returns the column namesint
getErrorCode()
Returns the error codejava.lang.String
getErrorMessage()
Returns the error messageint
getRowCount()
Returns the count of rows.java.util.List
getRowList()
Returns the list of rows.java.lang.String
getSQLQuery()
Returns the error sqlQueryjava.lang.String
getSQLState()
Returns the SQL stateboolean
isEmpty()
Returns true if no resultboolean
isError()
Returns true if an error occured during the query process
-
-
-
Field Detail
-
REVISION
public static final java.lang.String REVISION
- See Also:
- Constant Field Values
-
columnNames
protected java.lang.String[] columnNames
-
rowList
protected java.util.List rowList
-
isError
protected boolean isError
-
errorMessage
protected java.lang.String errorMessage
-
errorCode
protected int errorCode
-
sqlState
protected java.lang.String sqlState
-
sqlQuery
protected java.lang.String sqlQuery
-
-
Constructor Detail
-
SQLQueryResult
public SQLQueryResult(java.lang.String dataSource, java.lang.String select, java.lang.String from, java.lang.String orderby, java.lang.String[] whereParams, java.lang.String[] whereValues, boolean and, int maxRows)
Constructs a new SQLQueryResult. Build a SELECT query from given parameters.- Parameters:
dataSource
- the name of the data source (eg. "jdbc/TestDB")select
- the table filed to select or *from
- the table name to work with.orderby
- the order by parameterwhereParams
- an array of parameterswhereValues
- an array of parameters valueand
- should be 'AND' or 'OR' between parametersmaxRows
- the max rows limit; zero means there is no limit
-
SQLQueryResult
public SQLQueryResult(java.lang.String dataSource, java.lang.String sqlQuery, int maxRows)
Constructs a new SQLQueryResult.- Parameters:
dataSource
- the name of the data source (eg. "jdbc/TestDB")sqlQuery
- the SQL (SELECT) querymaxRows
- the max rows limit; zero means there is no limit- Since:
- jcms-5.5.0
-
SQLQueryResult
public SQLQueryResult(java.lang.String dataSource, java.lang.String sqlQuery, java.lang.Object[] params, int maxRows)
Constructs a new SQLQueryResult.- Parameters:
dataSource
- the name of the data source (eg. "jdbc/TestDB")sqlQuery
- the SQL query (may be a parametrized SQL query)params
- the query parametersmaxRows
- the max rows limit; zero means there is no limit- Since:
- jcms-5.5.0
-
SQLQueryResult
public SQLQueryResult(java.sql.Connection conn, java.lang.String sqlQuery, java.lang.Object[] params, int maxRows)
Constructs a new SQLQueryResult.- Parameters:
conn
- the JDBC connectionsqlQuery
- the SQL query (may be a parametrized SQL query)params
- the query parametersmaxRows
- the max rows limit; zero means there is no limit- Since:
- jcms-5.5.0
-
SQLQueryResult
public SQLQueryResult(java.sql.ResultSet rs)
Constructs a new SQLQueryResult.- Parameters:
rs
- a JDBC ResultSet- Since:
- jcms-5.5.0
-
-
Method Detail
-
getColumnNames
public java.lang.String[] getColumnNames()
Returns the column names- Returns:
- the column names
- Since:
- jcms-5.5.0
-
getColumnCount
public int getColumnCount()
Returns the column count- Returns:
- the column count
- Since:
- jcms-5.5.0
-
isEmpty
public boolean isEmpty()
Returns true if no result- Returns:
- true if no result
- Since:
- jcms-5.5.0
-
getRowList
public java.util.List getRowList()
Returns the list of rows. Each row is represented by a SQLQueryResult.Row object.- Returns:
- the list of rows.
- Since:
- jcms-5.5.0
-
getRowCount
public int getRowCount()
Returns the count of rows.- Returns:
- the count of rows.
- Since:
- jcms-5.5.0
-
isError
public boolean isError()
Returns true if an error occured during the query process- Returns:
- true if an error occured during the query process.
- Since:
- jcms-5.5.0
-
getErrorCode
public int getErrorCode()
Returns the error code- Returns:
- the error code.
- Since:
- jcms-5.5.0
- See Also:
SQLException.getErrorCode()
-
getSQLQuery
public java.lang.String getSQLQuery()
Returns the error sqlQuery- Returns:
- the error sqlQuery.
- Since:
- jcms-5.5.0
-
getErrorMessage
public java.lang.String getErrorMessage()
Returns the error message- Returns:
- the error message.
- Since:
- jcms-5.5.0
-
getSQLState
public java.lang.String getSQLState()
Returns the SQL state- Returns:
- the SQL state.
- Since:
- jcms-5.5.0
- See Also:
SQLException.getSQLState()
-
-