当前位置: 首页>>代码示例>>Java>>正文


Java PreparedStatement.setBytes方法代码示例

本文整理汇总了Java中java.sql.PreparedStatement.setBytes方法的典型用法代码示例。如果您正苦于以下问题:Java PreparedStatement.setBytes方法的具体用法?Java PreparedStatement.setBytes怎么用?Java PreparedStatement.setBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.sql.PreparedStatement的用法示例。


在下文中一共展示了PreparedStatement.setBytes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setGroupVisibility

import java.sql.PreparedStatement; //导入方法依赖的package包/类
@Override
public void setGroupVisibility(Connection txn, ContactId c, GroupId g,
		boolean shared) throws DbException {
	PreparedStatement ps = null;
	try {
		String sql = "UPDATE groupVisibilities SET shared = ?"
				+ " WHERE contactId = ? AND groupId = ?";
		ps = txn.prepareStatement(sql);
		ps.setBoolean(1, shared);
		ps.setInt(2, c.getInt());
		ps.setBytes(3, g.getBytes());
		int affected = ps.executeUpdate();
		if (affected < 0 || affected > 1) throw new DbStateException();
		ps.close();
	} catch (SQLException e) {
		tryToClose(ps);
		throw new DbException(e);
	}
}
 
开发者ID:rafjordao,项目名称:Nird2,代码行数:20,代码来源:JdbcDatabase.java

示例2: rowExists

import java.sql.PreparedStatement; //导入方法依赖的package包/类
private boolean rowExists(byte[] id) throws SQLException {
	assertNotNull(id);
	String sql = "SELECT NULL FROM foo WHERE uniqueID = ?";
	try {
		PreparedStatement ps = connection.prepareStatement(sql);
		ps.setBytes(1, id);
		ResultSet rs = ps.executeQuery();
		boolean found = rs.next();
		assertFalse(rs.next());
		rs.close();
		ps.close();
		return found;
	} catch (SQLException e) {
		connection.close();
		throw e;
	}
}
 
开发者ID:rafjordao,项目名称:Nird2,代码行数:18,代码来源:BasicH2Test.java

示例3: insertBatch

import java.sql.PreparedStatement; //导入方法依赖的package包/类
private void insertBatch(byte[][] ids, String[] names) throws SQLException {
	assertEquals(ids.length, names.length);
	String sql = "INSERT INTO foo (uniqueId, name) VALUES (?, ?)";
	try {
		PreparedStatement ps = connection.prepareStatement(sql);
		for (int i = 0; i < ids.length; i++) {
			if (ids[i] == null) ps.setNull(1, BINARY);
			else ps.setBytes(1, ids[i]);
			ps.setString(2, names[i]);
			ps.addBatch();
		}
		int[] batchAffected = ps.executeBatch();
		assertEquals(ids.length, batchAffected.length);
		for (int affected : batchAffected) assertEquals(1, affected);
		ps.close();
	} catch (SQLException e) {
		connection.close();
		throw e;
	}
}
 
开发者ID:rafjordao,项目名称:Nird2,代码行数:21,代码来源:BasicH2Test.java

示例4: lowerAckFlag

import java.sql.PreparedStatement; //导入方法依赖的package包/类
@Override
public void lowerAckFlag(Connection txn, ContactId c,
		Collection<MessageId> acked) throws DbException {
	PreparedStatement ps = null;
	try {
		String sql = "UPDATE statuses SET ack = FALSE"
				+ " WHERE messageId = ? AND contactId = ?";
		ps = txn.prepareStatement(sql);
		ps.setInt(2, c.getInt());
		for (MessageId m : acked) {
			ps.setBytes(1, m.getBytes());
			ps.addBatch();
		}
		int[] batchAffected = ps.executeBatch();
		if (batchAffected.length != acked.size())
			throw new DbStateException();
		for (int rows : batchAffected) {
			if (rows < 0) throw new DbStateException();
			if (rows > 1) throw new DbStateException();
		}
		ps.close();
	} catch (SQLException e) {
		tryToClose(ps);
		throw new DbException(e);
	}
}
 
开发者ID:rafjordao,项目名称:Nird2,代码行数:27,代码来源:JdbcDatabase.java

示例5: containsMessage

import java.sql.PreparedStatement; //导入方法依赖的package包/类
@Override
public boolean containsMessage(Connection txn, MessageId m)
		throws DbException {
	PreparedStatement ps = null;
	ResultSet rs = null;
	try {
		String sql = "SELECT NULL FROM messages WHERE messageId = ?";
		ps = txn.prepareStatement(sql);
		ps.setBytes(1, m.getBytes());
		rs = ps.executeQuery();
		boolean found = rs.next();
		if (rs.next()) throw new DbStateException();
		rs.close();
		ps.close();
		return found;
	} catch (SQLException e) {
		tryToClose(rs);
		tryToClose(ps);
		throw new DbException(e);
	}
}
 
开发者ID:rafjordao,项目名称:Nird2,代码行数:22,代码来源:JdbcDatabase.java

示例6: setMessageState

import java.sql.PreparedStatement; //导入方法依赖的package包/类
@Override
public void setMessageState(Connection txn, MessageId m, State state)
		throws DbException {
	PreparedStatement ps = null;
	try {
		String sql = "UPDATE messages SET state = ? WHERE messageId = ?";
		ps = txn.prepareStatement(sql);
		ps.setInt(1, state.getValue());
		ps.setBytes(2, m.getBytes());
		int affected = ps.executeUpdate();
		if (affected < 0 || affected > 1) throw new DbStateException();
		ps.close();
	} catch (SQLException e) {
		tryToClose(ps);
		throw new DbException(e);
	}
}
 
开发者ID:rafjordao,项目名称:Nird2,代码行数:18,代码来源:JdbcDatabase.java

示例7: removeGroupVisibility

import java.sql.PreparedStatement; //导入方法依赖的package包/类
@Override
public void removeGroupVisibility(Connection txn, ContactId c, GroupId g)
		throws DbException {
	PreparedStatement ps = null;
	try {
		String sql = "DELETE FROM groupVisibilities"
				+ " WHERE contactId = ? AND groupId = ?";
		ps = txn.prepareStatement(sql);
		ps.setInt(1, c.getInt());
		ps.setBytes(2, g.getBytes());
		int affected = ps.executeUpdate();
		if (affected != 1) throw new DbStateException();
		ps.close();
	} catch (SQLException e) {
		tryToClose(ps);
		throw new DbException(e);
	}
}
 
开发者ID:rafjordao,项目名称:Nird2,代码行数:19,代码来源:JdbcDatabase.java

示例8: testPrepareBindExecuteFetchVarbinary

import java.sql.PreparedStatement; //导入方法依赖的package包/类
@Test public void testPrepareBindExecuteFetchVarbinary() throws Exception {
  ConnectionSpec.getDatabaseLock().lock();
  try {
    final Connection connection = getLocalConnection();
    final String sql = "select x'de' || ? as c from (values (1, 'a'))";
    final PreparedStatement ps =
        connection.prepareStatement(sql);
    final ParameterMetaData parameterMetaData = ps.getParameterMetaData();
    assertThat(parameterMetaData.getParameterCount(), equalTo(1));

    ps.setBytes(1, new byte[]{65, 0, 66});
    final ResultSet resultSet = ps.executeQuery();
    assertTrue(resultSet.next());
    assertThat(resultSet.getBytes(1),
        equalTo(new byte[]{(byte) 0xDE, 65, 0, 66}));
    resultSet.close();
    ps.close();
    connection.close();
  } finally {
    ConnectionSpec.getDatabaseLock().unlock();
  }
}
 
开发者ID:apache,项目名称:calcite-avatica,代码行数:23,代码来源:RemoteDriverTest.java

示例9: setParameter

import java.sql.PreparedStatement; //导入方法依赖的package包/类
public void setParameter(PreparedStatement ps, int i, Object parameter, JdbcType jdbcType) throws SQLException
{
    if (parameter == null)
    {
        ps.setNull(i, Types.BINARY);
    }
    else
    {
        try
        {
            ps.setBytes(i, (byte[])parameter);
        }
        catch (Throwable e)
        {
            throw new SerializationException(e);
        }
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-core,代码行数:19,代码来源:ByteArrayTypeHandler.java

示例10: getGroupMetadata

import java.sql.PreparedStatement; //导入方法依赖的package包/类
@Override
public Metadata getGroupMetadata(Connection txn, GroupId g)
		throws DbException {
	PreparedStatement ps = null;
	ResultSet rs = null;
	try {
		String sql = "SELECT key, value FROM groupMetadata"
				+ " WHERE groupId = ?";
		ps = txn.prepareStatement(sql);
		ps.setBytes(1, g.getBytes());
		rs = ps.executeQuery();
		Metadata metadata = new Metadata();
		while (rs.next()) metadata.put(rs.getString(1), rs.getBytes(2));
		rs.close();
		ps.close();
		return metadata;
	} catch (SQLException e) {
		tryToClose(rs);
		tryToClose(ps);
		throw new DbException(e);
	}
}
 
开发者ID:rafjordao,项目名称:Nird2,代码行数:23,代码来源:JdbcDatabase.java

示例11: getName

import java.sql.PreparedStatement; //导入方法依赖的package包/类
private String getName(byte[] id) throws SQLException {
	assertNotNull(id);
	String sql = "SELECT name FROM foo WHERE uniqueID = ?";
	try {
		PreparedStatement ps = connection.prepareStatement(sql);
		ps.setBytes(1, id);
		ResultSet rs = ps.executeQuery();
		assertTrue(rs.next());
		String name = rs.getString(1);
		assertFalse(rs.next());
		rs.close();
		ps.close();
		return name;
	} catch (SQLException e) {
		connection.close();
		throw e;
	}
}
 
开发者ID:rafjordao,项目名称:Nird2,代码行数:19,代码来源:BasicH2Test.java

示例12: uploadPackage

import java.sql.PreparedStatement; //导入方法依赖的package包/类
@Override
public long uploadPackage(DataPackage dataPack) {
    long time = System.currentTimeMillis();
    try {
        Connection conn = DriverManager.getConnection(DB_URL + DATABASE, USER, PASS);
 
        String sql = "INSERT INTO " + MAIN_TABLE + " ("+ COL_ID +", "+ COL_DATA + ", " + COL_DESC + ") values (?, ?, ?)";
        PreparedStatement statement = conn.prepareStatement(sql);
        statement.setLong(1, time);
        statement.setBytes(2, dataPack.getData());
        statement.setString(3, dataPack.getDescription());
        
        int row = statement.executeUpdate();
        if (row > 0) {
            //Success
        }
        conn.close();
    } catch (SQLException ex) {
        ex.printStackTrace();
    }
    return time;
}
 
开发者ID:roscisz,项目名称:KernelHive,代码行数:23,代码来源:MySQLManager.java

示例13: removeOfferedMessages

import java.sql.PreparedStatement; //导入方法依赖的package包/类
@Override
public void removeOfferedMessages(Connection txn, ContactId c,
		Collection<MessageId> requested) throws DbException {
	PreparedStatement ps = null;
	try {
		String sql = "DELETE FROM offers"
				+ " WHERE contactId = ? AND messageId = ?";
		ps = txn.prepareStatement(sql);
		ps.setInt(1, c.getInt());
		for (MessageId m : requested) {
			ps.setBytes(2, m.getBytes());
			ps.addBatch();
		}
		int[] batchAffected = ps.executeBatch();
		if (batchAffected.length != requested.size())
			throw new DbStateException();
		for (int rows : batchAffected)
			if (rows != 1) throw new DbStateException();
		ps.close();
	} catch (SQLException e) {
		tryToClose(ps);
		throw new DbException(e);
	}
}
 
开发者ID:rafjordao,项目名称:Nird2,代码行数:25,代码来源:JdbcDatabase.java

示例14: addOfferedMessage

import java.sql.PreparedStatement; //导入方法依赖的package包/类
@Override
public void addOfferedMessage(Connection txn, ContactId c, MessageId m)
		throws DbException {
	PreparedStatement ps = null;
	ResultSet rs = null;
	try {
		String sql = "SELECT NULL FROM offers"
				+ " WHERE messageId = ? AND contactId = ?";
		ps = txn.prepareStatement(sql);
		ps.setBytes(1, m.getBytes());
		ps.setInt(2, c.getInt());
		rs = ps.executeQuery();
		boolean found = rs.next();
		if (rs.next()) throw new DbStateException();
		rs.close();
		ps.close();
		if (found) return;
		sql = "INSERT INTO offers (messageId, contactId) VALUES (?, ?)";
		ps = txn.prepareStatement(sql);
		ps.setBytes(1, m.getBytes());
		ps.setInt(2, c.getInt());
		int affected = ps.executeUpdate();
		if (affected != 1) throw new DbStateException();
		ps.close();
	} catch (SQLException e) {
		tryToClose(rs);
		tryToClose(ps);
		throw new DbException(e);
	}
}
 
开发者ID:rafjordao,项目名称:Nird2,代码行数:31,代码来源:JdbcDatabase.java

示例15: getMessageMetadataForValidator

import java.sql.PreparedStatement; //导入方法依赖的package包/类
@Override
public Metadata getMessageMetadataForValidator(Connection txn, MessageId m)
		throws DbException {
	PreparedStatement ps = null;
	ResultSet rs = null;
	try {
		String sql = "SELECT key, value FROM messageMetadata AS md"
				+ " JOIN messages AS m"
				+ " ON m.messageId = md.messageId"
				+ " WHERE (m.state = ? OR m.state = ?)"
				+ " AND md.messageId = ?";
		ps = txn.prepareStatement(sql);
		ps.setInt(1, DELIVERED.getValue());
		ps.setInt(2, PENDING.getValue());
		ps.setBytes(3, m.getBytes());
		rs = ps.executeQuery();
		Metadata metadata = new Metadata();
		while (rs.next()) metadata.put(rs.getString(1), rs.getBytes(2));
		rs.close();
		ps.close();
		return metadata;
	} catch (SQLException e) {
		tryToClose(rs);
		tryToClose(ps);
		throw new DbException(e);
	}
}
 
开发者ID:rafjordao,项目名称:Nird2,代码行数:28,代码来源:JdbcDatabase.java


注:本文中的java.sql.PreparedStatement.setBytes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。