use of net.sf.jasperreports.engine.JRParameter in project adempiere by adempiere.
the class JRQueryExecuter method getStatement.
/**
*
*/
private PreparedStatement getStatement(Connection conn) throws JRException {
PreparedStatement pstmt = null;
if (queryString != null && queryString.trim().length() > 0) {
try {
pstmt = conn.prepareStatement(queryString);
if (parameterNames != null && parameterNames.size() > 0) {
JRParameter parameter = null;
String parameterName = null;
Class clazz = null;
Object parameterValue = null;
for (int i = 0; i < parameterNames.size(); i++) {
parameterName = (String) parameterNames.get(i);
parameter = (JRParameter) parametersMap.get(parameterName);
clazz = parameter.getValueClass();
//FIXMEparameterValue = jrParameter.getValue();
parameterValue = parameterValues.get(parameterName);
if (clazz.equals(java.lang.Object.class)) {
if (parameterValue == null) {
pstmt.setNull(i + 1, Types.JAVA_OBJECT);
} else {
pstmt.setObject(i + 1, parameterValue);
}
} else if (clazz.equals(java.lang.Boolean.class)) {
if (parameterValue == null) {
pstmt.setNull(i + 1, Types.BIT);
} else {
pstmt.setBoolean(i + 1, ((Boolean) parameterValue).booleanValue());
}
} else if (clazz.equals(java.lang.Byte.class)) {
if (parameterValue == null) {
pstmt.setNull(i + 1, Types.TINYINT);
} else {
pstmt.setByte(i + 1, ((Byte) parameterValue).byteValue());
}
} else if (clazz.equals(java.lang.Double.class)) {
if (parameterValue == null) {
pstmt.setNull(i + 1, Types.DOUBLE);
} else {
pstmt.setDouble(i + 1, ((Double) parameterValue).doubleValue());
}
} else if (clazz.equals(java.lang.Float.class)) {
if (parameterValue == null) {
pstmt.setNull(i + 1, Types.FLOAT);
} else {
pstmt.setFloat(i + 1, ((Float) parameterValue).floatValue());
}
} else if (clazz.equals(java.lang.Integer.class)) {
if (parameterValue == null) {
pstmt.setNull(i + 1, Types.INTEGER);
} else {
pstmt.setInt(i + 1, ((Integer) parameterValue).intValue());
}
} else if (clazz.equals(java.lang.Long.class)) {
if (parameterValue == null) {
pstmt.setNull(i + 1, Types.BIGINT);
} else {
pstmt.setLong(i + 1, ((Long) parameterValue).longValue());
}
} else if (clazz.equals(java.lang.Short.class)) {
if (parameterValue == null) {
pstmt.setNull(i + 1, Types.SMALLINT);
} else {
pstmt.setShort(i + 1, ((Short) parameterValue).shortValue());
}
} else if (clazz.equals(java.math.BigDecimal.class)) {
if (parameterValue == null) {
pstmt.setNull(i + 1, Types.DECIMAL);
} else {
pstmt.setBigDecimal(i + 1, (BigDecimal) parameterValue);
}
} else if (clazz.equals(java.lang.String.class)) {
if (parameterValue == null) {
pstmt.setNull(i + 1, Types.VARCHAR);
} else {
pstmt.setString(i + 1, parameterValue.toString());
}
} else if (clazz.equals(java.util.Date.class)) {
if (parameterValue == null) {
pstmt.setNull(i + 1, Types.DATE);
} else {
pstmt.setDate(i + 1, new java.sql.Date(((java.util.Date) parameterValue).getTime()));
}
} else if (clazz.equals(java.sql.Timestamp.class)) {
if (parameterValue == null) {
pstmt.setNull(i + 1, Types.TIMESTAMP);
} else {
pstmt.setTimestamp(i + 1, (java.sql.Timestamp) parameterValue);
}
} else if (clazz.equals(java.sql.Time.class)) {
if (parameterValue == null) {
pstmt.setNull(i + 1, Types.TIME);
} else {
pstmt.setTime(i + 1, (java.sql.Time) parameterValue);
}
} else {
throw new JRException("Parameter type not supported in query : " + parameterName + " class " + clazz.getName());
}
}
}
} catch (SQLException e) {
throw new JRException("Error preparing statement for executing the report query : " + "\n\n" + queryString + "\n\n", e);
}
}
return pstmt;
}
Aggregations