Java Code Examples for java.sql.Time#setTime()

The following examples show how to use java.sql.Time#setTime() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SqlTimeSerializer.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public Time copy(Time from, Time reuse) {
	if (from == null) {
		return null;
	}
	reuse.setTime(from.getTime());
	return reuse;
}
 
Example 2
Source File: SqlTimeSerializer.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public Time deserialize(Time reuse, DataInputView source) throws IOException {
	final long v = source.readLong();
	if (v == Long.MIN_VALUE) {
		return null;
	}
	reuse.setTime(v);
	return reuse;
}
 
Example 3
Source File: SqlTimeSerializer.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public Time copy(Time from, Time reuse) {
	if (from == null) {
		return null;
	}
	reuse.setTime(from.getTime());
	return reuse;
}
 
Example 4
Source File: SqlTimeSerializer.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public Time deserialize(Time reuse, DataInputView source) throws IOException {
	final long v = source.readLong();
	if (v == Long.MIN_VALUE) {
		return null;
	}
	reuse.setTime(v);
	return reuse;
}
 
Example 5
Source File: PhoenixResultSet.java    From phoenix with Apache License 2.0 5 votes vote down vote up
@Override
public Time getTime(int columnIndex, Calendar cal) throws SQLException {
    checkCursorState();
    Time value = (Time)rowProjector.getColumnProjector(columnIndex-1).getValue(currentRow,
        PTime.INSTANCE, ptr);
    wasNull = (value == null);
    if (value == null) {
        return null;
    }
    cal.setTime(value);
    value.setTime(cal.getTimeInMillis());
    return value;
}
 
Example 6
Source File: TimeSerializer.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public Time copy(Time from, Time reuse) {
	if (from == null) {
		return null;
	}
	reuse.setTime(from.getTime());
	return reuse;
}
 
Example 7
Source File: SqlTimeSerializer.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public Time copy(Time from, Time reuse) {
	if (from == null) {
		return null;
	}
	reuse.setTime(from.getTime());
	return reuse;
}
 
Example 8
Source File: SqlTimeSerializer.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public Time deserialize(Time reuse, DataInputView source) throws IOException {
	final long v = source.readLong();
	if (v == Long.MIN_VALUE) {
		return null;
	}
	reuse.setTime(v);
	return reuse;
}
 
Example 9
Source File: PhoenixResultSet.java    From phoenix with Apache License 2.0 5 votes vote down vote up
@Override
public Time getTime(int columnIndex, Calendar cal) throws SQLException {
    checkCursorState();
    Time value = (Time)getRowProjector().getColumnProjector(columnIndex-1).getValue(currentRow,
        PTime.INSTANCE, ptr);
    wasNull = (value == null);
    if (value == null) {
        return null;
    }
    cal.setTime(value);
    value.setTime(cal.getTimeInMillis());
    return value;
}
 
Example 10
Source File: PhoenixResultSet.java    From phoenix with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public Time getTime(int columnIndex, Calendar cal) throws SQLException {
    checkCursorState();
    Time value = (Time)rowProjector.getColumnProjector(columnIndex-1).getValue(currentRow, PDataType.TIME, ptr);
    wasNull = (value == null);
    if (value == null) {
        return null;
    }
    cal.setTime(value);
    value.setTime(cal.getTimeInMillis());
    return value;
}
 
Example 11
Source File: Datatypes.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public static synchronized void add_one_row(Connection conn, int thread_id)
throws Exception {
	try {
		//initialize();
		PreparedStatement ps = conn.prepareStatement(
				" insert into Datatypes (id,t_char,t_blob," + "t_clob,"
				+ " t_date, t_decimal, t_decimal_nn, t_double, "
				+ " t_float, t_int, t_longint, t_numeric_large,"
				+ " t_real, t_smallint, t_time, t_timestamp,"
				+ " t_varchar) values ("
				+ " ?,?, ?,?, ?, ?,?, ?, ?, ?,?, ?, ?, ?, ?, ?,?)" 
				/* autoincrement feature added, so we need to specify the
				 * column name for prepared statement, otherwise auto increment
				 * column will think it is trying to update/insert a null value
				 * to the column.
				 */
				, Statement.RETURN_GENERATED_KEYS);
		InputStream streamIn = null;
		Reader streamReader = null;
		int ind = Rn.nextInt();
		double x;
		Date dt = new Date(1);
		Time tt = new Time(1);
		Timestamp ts = new Timestamp(1);
		String cs = "asdf qwerqwer 12341234 ZXCVZXCVZXCV !@#$!@#$ asdfasdf 1 q a z asdf ASDF qwerasdfzxcvasdfqwer1234asd#";
		ps.setInt(1, ind);
		// scramble the string
		int i1 = Math.abs(ind % 100);
		String cs2 = cs.substring(i1, 99) + cs.substring(0, i1);
		int i2 = i1 < 89 ? i1 + 10 : i1;
		ps.setString(2, cs2.substring(0, i2));
		//"t_blob"
		int blobLength = Rn.nextInt(102400 - 0 + 1) + 0;//to create a stream of random length between 0 and 100K
		streamIn = new LoopingAlphabetStream(blobLength);
		ps.setBinaryStream(3, streamIn, blobLength);
		//"t_clob
		int clobLength = Rn.nextInt(102400 - 0 + 1) + 0;//to create a stream of random length between 0 and 100K
		streamReader = new LoopingAlphabetReader(clobLength, CharAlphabet
				.modernLatinLowercase());
		ps.setCharacterStream(4, streamReader, clobLength);
		//"t_ndate"
		dt.setTime(Math.abs(Rn.nextLong() / 150000));
		ps.setDate(5, dt);
		//"t_decimal"
		x = Math.abs(Rn.nextInt() % 18);
		if (x > 5)
			x = 5;
		ps.setDouble(6, Math.abs(Rn.nextDouble() * Math.pow(10, x)));
		//"t_decimal_nn"
		ps.setDouble(7, Rn.nextDouble());
		//"t_double"
		ps.setDouble(8, Rn.nextDouble()
				* Math.pow(10, Math.abs(Rn.nextInt() % 300)));
		//"t_float"
		ps.setFloat(9, Rn.nextFloat()
				* (float) Math.pow(10, Math.abs(Rn.nextInt() % 30)));
		//"t_int"
		ps.setInt(10, Rn.nextInt());
		//"t_longint"
		ps.setLong(11, Rn.nextLong());
		//"t_numeric_large"
		x = Math.abs(Rn.nextInt() % 30);
		if (x > 30)
			x = 31;
		ps.setDouble(12, Math.abs(Rn.nextDouble() * Math.pow(10, x)));
		//"t_real"
		ps.setFloat(13, Rn.nextFloat()
				* (float) Math.pow(10, Math.abs(Rn.nextInt() % 7)));
		//"t_smallint"
		ps.setInt(14, Rn.nextInt() % (256 * 128));
		//"t_time"
		tt.setTime(Math.abs(Rn.nextInt()));
		ps.setTime(15, tt);
		//"t_timestamp"
		ts.setTime(Math.abs(Rn.nextLong() / 50000));
		ps.setTimestamp(16, ts);
		//"t_varchar"
		ps.setString(17, cs.substring(Math.abs(Rn.nextInt() % 100)));
		int rows = ps.executeUpdate();
		if (rows == 1) {

			ResultSet rs = ps.getGeneratedKeys();

			while (rs.next()) {
				ResultSetMetaData rsmd = rs.getMetaData();
				int numCols = rsmd.getColumnCount();
			}
		} else
			System.out.println("t" + thread_id + " insert failed");
		streamReader.close();
		streamIn.close();

	} catch (SQLException se) {
		if (se.getNextException() == null)
			throw se;
		String m = se.getNextException().getSQLState();
		System.out.println(se.getNextException().getMessage()
				+ " SQLSTATE: " + m);
	}
}
 
Example 12
Source File: Datatypes.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public static synchronized void add_one_row(Connection conn, int thread_id)
throws Exception {
	try {
		//initialize();
		PreparedStatement ps = conn.prepareStatement(
				" insert into Datatypes (id,t_char,t_blob," + "t_clob,"
				+ " t_date, t_decimal, t_decimal_nn, t_double, "
				+ " t_float, t_int, t_longint, t_numeric_large,"
				+ " t_real, t_smallint, t_time, t_timestamp,"
				+ " t_varchar) values ("
				+ " ?,?, ?,?, ?, ?,?, ?, ?, ?,?, ?, ?, ?, ?, ?,?)" 
				/* autoincrement feature added, so we need to specify the
				 * column name for prepared statement, otherwise auto increment
				 * column will think it is trying to update/insert a null value
				 * to the column.
				 */
				, Statement.RETURN_GENERATED_KEYS);
		InputStream streamIn = null;
		Reader streamReader = null;
		int ind = Rn.nextInt();
		double x;
		Date dt = new Date(1);
		Time tt = new Time(1);
		Timestamp ts = new Timestamp(1);
		String cs = "asdf qwerqwer 12341234 ZXCVZXCVZXCV !@#$!@#$ asdfasdf 1 q a z asdf ASDF qwerasdfzxcvasdfqwer1234asd#";
		ps.setInt(1, ind);
		// scramble the string
		int i1 = Math.abs(ind % 100);
		String cs2 = cs.substring(i1, 99) + cs.substring(0, i1);
		int i2 = i1 < 89 ? i1 + 10 : i1;
		ps.setString(2, cs2.substring(0, i2));
		//"t_blob"
		int blobLength = Rn.nextInt(102400 - 0 + 1) + 0;//to create a stream of random length between 0 and 100K
		streamIn = new LoopingAlphabetStream(blobLength);
		ps.setBinaryStream(3, streamIn, blobLength);
		//"t_clob
		int clobLength = Rn.nextInt(102400 - 0 + 1) + 0;//to create a stream of random length between 0 and 100K
		streamReader = new LoopingAlphabetReader(clobLength, CharAlphabet
				.modernLatinLowercase());
		ps.setCharacterStream(4, streamReader, clobLength);
		//"t_ndate"
		dt.setTime(Math.abs(Rn.nextLong() / 150000));
		ps.setDate(5, dt);
		//"t_decimal"
		x = Math.abs(Rn.nextInt() % 18);
		if (x > 5)
			x = 5;
		ps.setDouble(6, Math.abs(Rn.nextDouble() * Math.pow(10, x)));
		//"t_decimal_nn"
		ps.setDouble(7, Rn.nextDouble());
		//"t_double"
		ps.setDouble(8, Rn.nextDouble()
				* Math.pow(10, Math.abs(Rn.nextInt() % 300)));
		//"t_float"
		ps.setFloat(9, Rn.nextFloat()
				* (float) Math.pow(10, Math.abs(Rn.nextInt() % 30)));
		//"t_int"
		ps.setInt(10, Rn.nextInt());
		//"t_longint"
		ps.setLong(11, Rn.nextLong());
		//"t_numeric_large"
		x = Math.abs(Rn.nextInt() % 30);
		if (x > 30)
			x = 31;
		ps.setDouble(12, Math.abs(Rn.nextDouble() * Math.pow(10, x)));
		//"t_real"
		ps.setFloat(13, Rn.nextFloat()
				* (float) Math.pow(10, Math.abs(Rn.nextInt() % 7)));
		//"t_smallint"
		ps.setInt(14, Rn.nextInt() % (256 * 128));
		//"t_time"
		tt.setTime(Math.abs(Rn.nextInt()));
		ps.setTime(15, tt);
		//"t_timestamp"
		ts.setTime(Math.abs(Rn.nextLong() / 50000));
		ps.setTimestamp(16, ts);
		//"t_varchar"
		ps.setString(17, cs.substring(Math.abs(Rn.nextInt() % 100)));
		int rows = ps.executeUpdate();
		if (rows == 1) {

			ResultSet rs = ps.getGeneratedKeys();

			while (rs.next()) {
				ResultSetMetaData rsmd = rs.getMetaData();
				int numCols = rsmd.getColumnCount();
			}
		} else
			System.out.println("t" + thread_id + " insert failed");
		streamReader.close();
		streamIn.close();

	} catch (SQLException se) {
		if (se.getNextException() == null)
			throw se;
		String m = se.getNextException().getSQLState();
		System.out.println(se.getNextException().getMessage()
				+ " SQLSTATE: " + m);
	}
}
 
Example 13
Source File: TimeSerializer.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public Time deserialize(Time reuse, DataInputView source) throws IOException {
	int time = source.readInt();
	reuse.setTime(time - LOCAL_TZ.getOffset(time));
	return reuse;
}
 
Example 14
Source File: Datatypes.java    From spliceengine with GNU Affero General Public License v3.0 4 votes vote down vote up
public static synchronized void add_one_row(Connection conn, int thread_id)
throws Exception {
	try {
		//initialize();
		PreparedStatement ps = conn.prepareStatement(
				" insert into Datatypes (id,t_char,t_blob," + "t_clob,"
				+ " t_date, t_decimal, t_decimal_nn, t_double, "
				+ " t_float, t_int, t_longint, t_numeric_large,"
				+ " t_real, t_smallint, t_time, t_timestamp,"
				+ " t_varchar) values ("
				+ " ?,?, ?,?, ?, ?,?, ?, ?, ?,?, ?, ?, ?, ?, ?,?)" 
				/* autoincrement feature added, so we need to specify the
				 * column name for prepared statement, otherwise auto increment
				 * column will think it is trying to update/insert a null value
				 * to the column.
				 */
				, Statement.RETURN_GENERATED_KEYS);
		InputStream streamIn = null;
		Reader streamReader = null;
		int ind = Rn.nextInt();
		double x;
		Date dt = new Date(1);
		Time tt = new Time(1);
		Timestamp ts = new Timestamp(1);
		String cs = "asdf qwerqwer 12341234 ZXCVZXCVZXCV !@#$!@#$ asdfasdf 1 q a z asdf ASDF qwerasdfzxcvasdfqwer1234asd#";
		ps.setInt(1, ind);
		// scramble the string
		int i1 = Math.abs(ind % 100);
		String cs2 = cs.substring(i1, 99) + cs.substring(0, i1);
		int i2 = i1 < 89 ? i1 + 10 : i1;
		ps.setString(2, cs2.substring(0, i2));
		//"t_blob"
		int blobLength = Rn.nextInt(102400 - 0 + 1) + 0;//to create a stream of random length between 0 and 100K
		streamIn = new LoopingAlphabetStream(blobLength);
		ps.setBinaryStream(3, streamIn, blobLength);
		//"t_clob
		int clobLength = Rn.nextInt(102400 - 0 + 1) + 0;//to create a stream of random length between 0 and 100K
		streamReader = new LoopingAlphabetReader(clobLength, CharAlphabet
				.modernLatinLowercase());
		ps.setCharacterStream(4, streamReader, clobLength);
		//"t_ndate"
		dt.setTime(Math.abs(Rn.nextLong() / 150000));
		ps.setDate(5, dt);
		//"t_decimal"
		x = Math.abs(Rn.nextInt() % 18);
		if (x > 5)
			x = 5;
		ps.setDouble(6, Math.abs(Rn.nextDouble() * Math.pow(10, x)));
		//"t_decimal_nn"
		ps.setDouble(7, Rn.nextDouble());
		//"t_double"
		ps.setDouble(8, Rn.nextDouble()
				* Math.pow(10, Math.abs(Rn.nextInt() % 300)));
		//"t_float"
		ps.setFloat(9, Rn.nextFloat()
				* (float) Math.pow(10, Math.abs(Rn.nextInt() % 30)));
		//"t_int"
		ps.setInt(10, Rn.nextInt());
		//"t_longint"
		ps.setLong(11, Rn.nextLong());
		//"t_numeric_large"
		x = Math.abs(Rn.nextInt() % 30);
		if (x > 30)
			x = 31;
		ps.setDouble(12, Math.abs(Rn.nextDouble() * Math.pow(10, x)));
		//"t_real"
		ps.setFloat(13, Rn.nextFloat()
				* (float) Math.pow(10, Math.abs(Rn.nextInt() % 7)));
		//"t_smallint"
		ps.setInt(14, Rn.nextInt() % (256 * 128));
		//"t_time"
		tt.setTime(Math.abs(Rn.nextInt()));
		ps.setTime(15, tt);
		//"t_timestamp"
		ts.setTime(Math.abs(Rn.nextLong() / 50000));
		ps.setTimestamp(16, ts);
		//"t_varchar"
		ps.setString(17, cs.substring(Math.abs(Rn.nextInt() % 100)));
		int rows = ps.executeUpdate();
		if (rows == 1) {

			ResultSet rs = ps.getGeneratedKeys();

			while (rs.next()) {
				ResultSetMetaData rsmd = rs.getMetaData();
				int numCols = rsmd.getColumnCount();
			}
		} else
			System.out.println("t" + thread_id + " insert failed");
		streamReader.close();
		streamIn.close();

	} catch (SQLException se) {
		if (se.getNextException() == null)
			throw se;
		String m = se.getNextException().getSQLState();
		System.out.println(se.getNextException().getMessage()
				+ " SQLSTATE: " + m);
	}
}