List of usage examples for java.sql Date Date
public Date(long date)
From source file:org.waarp.common.database.data.AbstractDbData.java
/** * Set the values from the Json node to the current object (no database access) * /*from ww w .j a v a 2 s.com*/ * @param node * @param ignorePrimaryKey * True will ignore primaryKey from Json * @throws WaarpDatabaseSqlException */ public void setFromJson(ObjectNode node, boolean ignorePrimaryKey) throws WaarpDatabaseSqlException { DbValue[] list = allFields; if (ignorePrimaryKey) { list = otherFields; } for (DbValue value : list) { if (value.column.equalsIgnoreCase("UPDATEDINFO")) { continue; } JsonNode item = node.get(value.column); if (item != null && !item.isMissingNode() && !item.isNull()) { isSaved = false; switch (value.type) { case Types.VARCHAR: case Types.LONGVARCHAR: value.setValue(item.asText()); break; case Types.BIT: value.setValue(item.asBoolean()); break; case Types.TINYINT: case Types.SMALLINT: case Types.INTEGER: value.setValue(item.asInt()); break; case Types.BIGINT: value.setValue(item.asLong()); break; case Types.REAL: case Types.DOUBLE: value.setValue(item.asDouble()); break; case Types.VARBINARY: try { value.setValue(item.binaryValue()); } catch (IOException e) { throw new WaarpDatabaseSqlException("Issue while assigning array of bytes", e); } break; case Types.DATE: value.setValue(new Date(item.asLong())); break; case Types.TIMESTAMP: value.setValue(new Timestamp(item.asLong())); break; case Types.CLOB: case Types.BLOB: default: throw new WaarpDatabaseSqlException("Unsupported type: " + value.type); } } } setFromArray(); }
From source file:dk.netarkivet.archive.arcrepositoryadmin.ReplicaCacheHelpers.java
/** * Method for updating the checksum status of a replicafileinfo instance. * Updates the following fields for the entry in the replicafileinfo: * <br/> checksum_status = CORRUPT. * <br/> checksum_checkdatetime = current time. * * The replicafileinfo is in the filelist. * * @param replicafileinfoId The id of the replicafileinfo. * @param con An open connection to the archive database *//*from w ww . j a v a2 s.com*/ protected static void updateReplicaFileInfoChecksumCorrupt(long replicafileinfoId, Connection con) { PreparedStatement statement = null; try { // The SQL statement final String sql = "UPDATE replicafileinfo SET checksum_status = ?, " + "checksum_checkdatetime = ?, upload_status = ? " + "WHERE replicafileinfo_guid = ?"; Date now = new Date(Calendar.getInstance().getTimeInMillis()); // complete the SQL statement. statement = DBUtils.prepareStatement(con, sql, ChecksumStatus.CORRUPT.ordinal(), now, ReplicaStoreState.UPLOAD_FAILED.ordinal(), replicafileinfoId); // execute the SQL statement statement.executeUpdate(); con.commit(); } catch (Exception e) { String msg = "Problems updating the replicafileinfo."; log.warn(msg); throw new IOFailure(msg, e); } finally { DBUtils.closeStatementIfOpen(statement); } }
From source file:adalid.commons.util.TimeUtils.java
public static Date addDate(java.util.Date date, int addend, char unit) { if (date == null) { return null; }//from ww w.j av a 2 s. c om Calendar c = newDateCalendar(date); if (addend != 0) { switch (unit) { case 'Y': c.add(Calendar.YEAR, addend); break; case 'M': c.add(Calendar.MONTH, addend); break; case 'D': c.add(Calendar.DAY_OF_MONTH, addend); break; default: break; } } return new Date(c.getTimeInMillis()); }
From source file:jp.co.rediscovery.arflight.controllers.DeviceController.java
/** DeviceController?start????(mARDeviceController?, onConnect???) */ protected void onStarted() { if (DEBUG)/*from www. j a va 2 s.c o m*/ Log.v(TAG, "onStarted:"); // only with RollingSpider in version 1.97 : date and time must be sent to permit a reconnection // NewAPI?????????? final Date currentDate = new Date(System.currentTimeMillis()); sendDate(currentDate); sendTime(currentDate); if (DEBUG) Log.v(TAG, "onStarted:"); }
From source file:org.kepler.objectmanager.cache.CacheManager.java
/** * @param type/*from w w w . j ava2s . c o m*/ * @return */ public Vector<CacheContent> getCachedContents(String type) { Vector<CacheContent> contents = new Vector<CacheContent>(); String query = "SELECT NAME,LSID,DATE,FILE,TYPE,CLASSNAME FROM " + CACHETABLENAME; if (!type.trim().equals("")) { query += " WHERE TYPE = '" + type + "'"; } try { ResultSet rs = null; try { rs = _stmt.executeQuery(query); if (rs == null) throw new SQLException("Query Failed: " + query); while (rs.next()) { CacheContent cc = new CacheContent(); cc.setName(rs.getString(1)); try { KeplerLSID lsid = new KeplerLSID(rs.getString(2)); cc.setLsid(lsid); Long l = Long.parseLong(rs.getString(3)); Date d = new Date(l); cc.setDateChanged(d); File f = new File(rs.getString(4)); cc.setFile(f); cc.setType(rs.getString(5)); cc.setClassName(rs.getString(6)); contents.add(cc); } catch (Exception e) { e.printStackTrace(); } } } finally { if (rs != null) { rs.close(); } } } catch (SQLException e1) { e1.printStackTrace(); contents = new Vector<CacheContent>(); } return contents; }
From source file:com.taobao.adfs.database.tdhsocket.client.response.TDHSResutSet.java
public Date getDate(int columnIndex, Calendar cal) throws SQLException { Long time = ConvertUtil.getTimeFromString(this.getString(columnIndex), cal); return time == null ? null : new Date(time); }
From source file:ips1ap101.lib.base.util.StrUtils.java
public static Object getObjeto(String string, Class<?> clazz) { if (string == null || clazz == null) { return null; }//w w w. j a v a2s . c om try { String value = StringUtils.trimToNull(string); if (value == null) { return null; } else if (Character.class.isAssignableFrom(clazz)) { return new Character(value.charAt(0)); } else if (String.class.isAssignableFrom(clazz)) { // ALFANUMERICO return string; } else if (Boolean.class.isAssignableFrom(clazz)) { return BitUtils.valueOf(value); } else if (Byte.class.isAssignableFrom(clazz)) { return new Byte(new BigDecimal(value).byteValue()); } else if (Short.class.isAssignableFrom(clazz)) { return new Short(new BigDecimal(value).shortValue()); } else if (Integer.class.isAssignableFrom(clazz)) { // ENTERO return new Integer(new BigDecimal(value).intValue()); } else if (Long.class.isAssignableFrom(clazz)) { return new Long(new BigDecimal(value).longValue()); } else if (Float.class.isAssignableFrom(clazz)) { return new Float(new BigDecimal(value).floatValue()); } else if (Double.class.isAssignableFrom(clazz)) { return new Double(new BigDecimal(value).doubleValue()); } else if (BigInteger.class.isAssignableFrom(clazz)) { // ENTERO_GRANDE return new Long(new BigDecimal(value).longValue()); } else if (BigDecimal.class.isAssignableFrom(clazz)) { // NUMERICO return new BigDecimal(value); } else if (java.util.Date.class.isAssignableFrom(clazz)) { // FECHA_HORA java.util.Date dateTime = TimeUtils.parse(value); if (Timestamp.class.isAssignableFrom(clazz)) { return new Timestamp(dateTime.getTime()); } else if (Time.class.isAssignableFrom(clazz)) { return new Time(dateTime.getTime()); } else if (Date.class.isAssignableFrom(clazz)) { return new Date(dateTime.getTime()); } else { return dateTime; } } // } catch (NumberFormatException e) { // return null; } catch (RuntimeException e) { return null; } return null; }
From source file:com.taobao.adfs.database.tdhsocket.client.response.TDHSResutSet.java
public Date getDate(String columnLabel, Calendar cal) throws SQLException { Long time = ConvertUtil.getTimeFromString(this.getString(this.findColumn(columnLabel)), cal); return time == null ? null : new Date(time); }
From source file:dk.netarkivet.archive.arcrepositoryadmin.ReplicaCacheHelpers.java
/** * Method for updating the checksum status of a replicafileinfo instance. * Updates the following fields for the entry in the replicafileinfo: * <br/> checksum_status = UNKNOWN. * <br/> checksum_checkdatetime = current time. * * The replicafileinfo is in the filelist. * * @param replicafileinfoId The id of the replicafileinfo. * @param con An open connection to the archive database *//*from www . j a va 2s .c om*/ protected static void updateReplicaFileInfoChecksumUnknown(long replicafileinfoId, Connection con) { PreparedStatement statement = null; try { // The SQL statement final String sql = "UPDATE replicafileinfo SET checksum_status = ?, " + "checksum_checkdatetime = ? " + "WHERE replicafileinfo_guid = ?"; Date now = new Date(Calendar.getInstance().getTimeInMillis()); // complete the SQL statement. statement = DBUtils.prepareStatement(con, sql, ChecksumStatus.UNKNOWN.ordinal(), now, replicafileinfoId); // execute the SQL statement statement.executeUpdate(); con.commit(); } catch (Exception e) { String msg = "Problems updating the replicafileinfo."; log.warn(msg); throw new IOFailure(msg, e); } finally { DBUtils.closeStatementIfOpen(statement); } }
From source file:com.tremolosecurity.provisioning.core.providers.BasicDB.java
private PreparedStatement updateField(User user, Connection con, StringBuffer b, String attrName, String userID, int userIDnum) throws SQLException { b.setLength(0);// ww w . ja v a2 s .c o m b.append("UPDATE ").append(this.userTable).append(" SET "); this.getFieldName(attrName, b).append("=? WHERE "); this.getFieldName(this.userPrimaryKey, b).append("=?"); PreparedStatement ps = con.prepareStatement(b.toString()); ps.setString(1, user.getAttribs().get(attrName).getValues().get(0)); if (userIDnum != -1) { ps.setInt(2, userIDnum); } else { Attribute.DataType tat = user.getAttribs().get(attrName).getDataType(); switch (tat) { case string: ps.setString(2, userID); break; case intNum: ps.setInt(2, Integer.parseInt(userID)); break; case longNum: ps.setLong(2, Long.parseLong(userID)); break; case date: ps.setDate(2, new Date(ISODateTimeFormat.date().parseDateTime(userID).getMillis())); break; case timeStamp: ps.setTimestamp(2, new Timestamp(ISODateTimeFormat.dateTime().parseDateTime(userID).getMillis())); break; } ps.setString(2, userID); } ps.executeUpdate(); return ps; }