List of usage examples for java.sql PreparedStatement setDate
void setDate(int parameterIndex, java.sql.Date x) throws SQLException;
java.sql.Date
value using the default time zone of the virtual machine that is running the application. From source file:com.wabacus.system.datatype.CDateType.java
public void setPreparedStatementValue(int iindex, String value, PreparedStatement pstmt, AbsDatabaseType dbtype) throws SQLException { log.debug("setDate(" + iindex + "," + value + ")"); pstmt.setDate(iindex, (java.sql.Date) label2value(value)); }
From source file:org.oscarehr.common.dao.DemographicDao.java
public static List<Integer> getDemographicIdsAlteredSinceTime(Date value) { Connection c = null;//from www .j av a 2 s. c o m try { c = DbConnectionFilter.getThreadLocalDbConnection(); PreparedStatement ps = c.prepareStatement( "SELECT DISTINCT demographic_no FROM log WHERE dateTime >= ? and action != 'read'"); ps.setDate(1, new java.sql.Date(value.getTime())); ResultSet rs = ps.executeQuery(); ArrayList<Integer> results = new ArrayList<Integer>(); while (rs.next()) { if (rs.getInt(1) != 0) { results.add(rs.getInt(1)); } } return (results); } catch (SQLException e) { throw (new PersistenceException(e)); } finally { SqlUtils.closeResources(c, null, null); } }
From source file:com.wabacus.system.datatype.CDateType.java
public void setPreparedStatementValue(int index, Date dateValue, PreparedStatement pstmt) throws SQLException { log.debug("setDate(" + index + "," + dateValue + ")"); if (dateValue == null) { pstmt.setDate(index, null); } else {/* w w w . java2s . co m*/ pstmt.setDate(index, new java.sql.Date(dateValue.getTime())); } }
From source file:org.rti.zcore.dar.report.ZEPRSSharedItems.java
static protected int getTotalAnteReattendances(Date beginDate, Date endDate, int siteID, Connection conn) { int count = 0; try {/*from www.jav a 2 s .c o m*/ // First, get the form id for the Antenatal Record Exam and Subsequent Visits form // int formID = ZEPRSUtils.getFormID("Antenatal Record Exam and Subsequent Visits"); int formID = 80; // Next, determine how many times the Anenatal Record Exam and Subsequent Visits // form was submitted //count = ZEPRSUtils.getEncountersCount(formID, "routineante", beginDate, endDate, siteID, conn); // Get the id's of patients who have had routine ante visits during the time period ResultSet rs = null; try { String sql = "SELECT patient_id FROM encounter\n" + "WHERE form_id = ? AND date_visit >= ? AND date_visit <= ? AND site_id = ? GROUP BY patient_id"; PreparedStatement ps = conn.prepareStatement(sql); ps.setString(1, Integer.toString(formID)); ps.setDate(2, beginDate); ps.setDate(3, endDate); ps.setInt(4, siteID); rs = ps.executeQuery(); while (rs.next()) { int patientId = rs.getInt(1); // how many routine ante visits have they had? if >1, then it's a re-attendance sql = "SELECT count(*) FROM encounter\n" + "WHERE form_id = ? AND site_id = ? AND patient_id=?"; ps = conn.prepareStatement(sql); ps.setInt(1, formID); ps.setInt(2, siteID); ps.setInt(3, patientId); ResultSet rs2 = ps.executeQuery(); while (rs2.next()) { int visits = rs2.getInt(1); if (visits > 1) { count = count + 1; } } } rs.close(); } catch (SQLException e) { e.printStackTrace(); } return count; } catch (Exception e) { log.error(e); } return count; }
From source file:org.apache.phoenix.util.TestUtil.java
public static void setRowKeyColumns(PreparedStatement stmt, int i) throws SQLException { // insert row stmt.setString(1, "varchar" + String.valueOf(i)); stmt.setString(2, "char" + String.valueOf(i)); stmt.setInt(3, i);/*from w w w . j a va 2 s . c o m*/ stmt.setLong(4, i); stmt.setBigDecimal(5, new BigDecimal(i * 0.5d)); Date date = new Date(DateUtil.parseDate("2015-01-01 00:00:00").getTime() + (i - 1) * MILLIS_IN_DAY); stmt.setDate(6, date); }
From source file:com.sf.ddao.factory.param.ParameterHelper.java
public static void bind(PreparedStatement preparedStatement, int idx, Object param, Class<?> clazz, Context context) throws SQLException { if (clazz == Integer.class || clazz == Integer.TYPE) { preparedStatement.setInt(idx, (Integer) param); } else if (clazz == String.class) { preparedStatement.setString(idx, (String) param); } else if (clazz == Long.class || clazz == Long.TYPE) { preparedStatement.setLong(idx, (Long) param); } else if (clazz == Boolean.class || clazz == Boolean.TYPE) { preparedStatement.setBoolean(idx, (Boolean) param); } else if (BigInteger.class.isAssignableFrom(clazz)) { BigInteger bi = (BigInteger) param; preparedStatement.setBigDecimal(idx, new BigDecimal(bi)); } else if (Timestamp.class.isAssignableFrom(clazz)) { preparedStatement.setTimestamp(idx, (Timestamp) param); } else if (Date.class.isAssignableFrom(clazz)) { if (!java.sql.Date.class.isAssignableFrom(clazz)) { param = new java.sql.Date(((Date) param).getTime()); }//from w ww. j a v a2 s.co m preparedStatement.setDate(idx, (java.sql.Date) param); } else if (BoundParameter.class.isAssignableFrom(clazz)) { ((BoundParameter) param).bindParam(preparedStatement, idx, context); } else { throw new SQLException("Unimplemented type mapping for " + clazz); } }
From source file:org.rti.zcore.dar.report.ZEPRSSharedItems.java
static protected int getTotalFirstPostAttendances(Date beginDate, Date endDate, int siteID, Connection conn) { int count = 0; try {// w ww . ja v a 2 s. c o m // Connection conn = ZEPRSUtils.getZEPRSConnection(); // First, get the form id for the Postnatal Maternal Visit form // int formID = ZEPRSUtils.getFormID("Postnatal Maternal Visit"); int formID = 28; // Next, retrieve all encounters associated with this form // for the time period in question ResultSet rs = ZEPRSUtils.getEncounters(formID, "postnatalmaternalvisit", beginDate, endDate, siteID, conn, true); // loop through all records and eliminate any that are not // the first postnatal attendance for this patient int prevPatientID = 0; int firstPostnatalCount = 0; while (rs.next()) { // for any new patiend id, check to see if this patient // was associated with a previous Postnatal Maternal Visit // // limit check to those associated with THIS pregnancy int patientID = rs.getInt("patient_id"); int pregnancyId = rs.getInt("pregnancy_id"); if (patientID != prevPatientID) { String sql = "SELECT count(*) FROM encounter " + "WHERE form_id = ? AND pregnancy_id = ? AND date_visit < ?"; PreparedStatement ps = conn.prepareStatement(sql); ps.setInt(1, formID); ps.setInt(2, pregnancyId); ps.setDate(3, beginDate); ResultSet rs2 = ps.executeQuery(); // any result that comes back implies that this patient // has had a postnatal visit before this time period if (!rs2.next()) { firstPostnatalCount++; } } } rs.close(); return firstPostnatalCount; } catch (Exception e) { // TBD } return count; }
From source file:net.freechoice.dao.impl.Dao_Transaction.java
@DBSpec(dialect = Dialect.PostgreSQL) @Override// w ww . j a v a 2 s .com public List<FC_Transaction> getTransactionsOnDate(final Date date) { return getJdbcTemplate().query(new PreparedStatementCreator() { @Override public PreparedStatement createPreparedStatement(Connection con) throws SQLException { PreparedStatement ps = con.prepareStatement(SELECT_FROM_FC_TRANSACTION + "where is_valid = true and time_committed::date = ?" + Dao_Transaction.TIME_DESCEND); ps.setDate(1, date); return ps; } }, mapper); }
From source file:com.fusesource.examples.horo.db.typehandler.DateTimeTypeHandler.java
@Override public void setNonNullParameter(PreparedStatement preparedStatement, int i, DateTime dateTime, JdbcType jdbcType) throws SQLException { Validate.notNull(dateTime, "dateTime is null"); if ((jdbcType == null) || (jdbcType.equals(JdbcType.DATE))) { preparedStatement.setDate(i, new java.sql.Date(dateTime.getMillis())); } else {//from w ww. java 2s . com throw new UnsupportedOperationException("Unable to convert DateTime to " + jdbcType.toString()); } }
From source file:test.other.T_DaoTest.java
public void test3() throws SQLException { PreparedStatement ps = conn.prepareStatement("select content from fc_post where time_posted::date = ?"); ps.setDate(1, null); System.out.println(ps);/*from w ww . j a va2 s.c om*/ ResultSet rs = ps.executeQuery(); while (rs.next()) { System.out.println(rs.getString(1)); } // Dao_User dao_User = new Dao_User(); //// dao_User.is // V_Post post; // Map_Post postmap = new Map_Post(); // ResultSet rs = conn.prepareStatement("select * from v_post where id = 4 ").executeQuery(); // rs.next(); // post = postmap.mapRow(rs, 1); // System.out.println(post.content); // System.out.println(post.title); }