List of usage examples for java.sql CallableStatement setNull
void setNull(String parameterName, int sqlType) throws SQLException;
NULL
. From source file:shnakkydoodle.measuring.provider.MetricsProviderSQLServer.java
/** * List all metric sla's or by metric alarmid * /*from www. j ava2 s. c o m*/ * @param metricAlarmId * * @return ArrayList<MetricSLA> */ @Override public ArrayList<MetricSLA> getMetricSlas(Integer metricAlarmId) { Connection conn = null; CallableStatement stmt = null; ResultSet rs = null; // create a container for the data ArrayList<MetricSLA> metricSlaList = new ArrayList<MetricSLA>(); try { Class.forName("net.sourceforge.jtds.jdbc.Driver"); conn = DriverManager.getConnection(this.host + ";user=" + this.username + ";password=" + this.password); stmt = conn.prepareCall("uspMetricSla_GetByMetricAlarmId(?)"); if (metricAlarmId == null) stmt.setNull(1, Types.NULL); else stmt.setInt(1, metricAlarmId); rs = stmt.executeQuery(); while (rs.next()) { AlarmMetricAlarm alarmMetricAlarm = new AlarmMetricAlarm(); alarmMetricAlarm = getMetricAlarm(rs.getInt("MetricAlarmId"), null); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); MetricSLA dataitem = new MetricSLA(); dataitem.setMetricSLAId(rs.getInt("MetricSlaId")); dataitem.setAlarmMetricAlarm(alarmMetricAlarm); dataitem.setSLAName(rs.getString("Name")); dataitem.setSLADescription(rs.getString("Description")); dataitem.setPercentage(rs.getDouble("Percentage")); dataitem.setDateModified(sdf.parse(rs.getString("DateModified"))); dataitem.setDateCreated(sdf.parse(rs.getString("DateCreated"))); metricSlaList.add(dataitem); } } catch (SQLException e) { this.loggingManager.LogError("Error : " + e.getClass().getName(), e.getMessage()); e.printStackTrace(); } catch (ClassNotFoundException e) { this.loggingManager.LogError("Error : " + e.getClass().getName(), e.getMessage()); e.printStackTrace(); } catch (ParseException e) { this.loggingManager.LogError("Error : " + e.getClass().getName(), e.getMessage()); e.printStackTrace(); } finally { DbUtils.closeQuietly(rs); DbUtils.closeQuietly(stmt); DbUtils.closeQuietly(conn); } return metricSlaList; }
From source file:shnakkydoodle.measuring.provider.MetricsProviderSQLServer.java
/** * Get metric sla by MetricSlaId/Sla Name * /*ww w .j a v a 2s . c o m*/ * @param metricSlaId * @param slaName * @return MetricSLA */ @Override public MetricSLA getMetricSla(Integer metricSlaId, String slaName) { Connection conn = null; CallableStatement stmt = null; ResultSet rs = null; // create a container for the data MetricSLA dataitem = null; try { Class.forName("net.sourceforge.jtds.jdbc.Driver"); conn = DriverManager.getConnection(this.host + ";user=" + this.username + ";password=" + this.password); stmt = conn.prepareCall("uspMetricSla_Get(?,?)"); if (metricSlaId == null) stmt.setNull(1, Types.NULL); else stmt.setInt(1, metricSlaId); if (slaName == null) stmt.setNull(2, Types.NULL); else stmt.setString(2, slaName); rs = stmt.executeQuery(); while (rs.next()) { AlarmMetricAlarm alarmMetricAlarm = new AlarmMetricAlarm(); alarmMetricAlarm = getMetricAlarm(rs.getInt("MetricAlarmId"), null); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); dataitem = new MetricSLA(); dataitem.setMetricSLAId(rs.getInt("MetricSlaId")); dataitem.setAlarmMetricAlarm(alarmMetricAlarm); dataitem.setSLAName(rs.getString("Name")); dataitem.setSLADescription(rs.getString("Description")); dataitem.setPercentage(rs.getDouble("Percentage")); dataitem.setDateModified(sdf.parse(rs.getString("DateModified"))); dataitem.setDateCreated(sdf.parse(rs.getString("DateCreated"))); } } catch (SQLException e) { this.loggingManager.LogError("Error : " + e.getClass().getName(), e.getMessage()); e.printStackTrace(); } catch (ClassNotFoundException e) { this.loggingManager.LogError("Error : " + e.getClass().getName(), e.getMessage()); e.printStackTrace(); } catch (ParseException e) { this.loggingManager.LogError("Error : " + e.getClass().getName(), e.getMessage()); e.printStackTrace(); } finally { DbUtils.closeQuietly(rs); DbUtils.closeQuietly(stmt); DbUtils.closeQuietly(conn); } return dataitem; }