本文整理汇总了Java中java.sql.ResultSet.wasNull方法的典型用法代码示例。如果您正苦于以下问题:Java ResultSet.wasNull方法的具体用法?Java ResultSet.wasNull怎么用?Java ResultSet.wasNull使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.sql.ResultSet
的用法示例。
在下文中一共展示了ResultSet.wasNull方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fillColValue
import java.sql.ResultSet; //导入方法依赖的package包/类
boolean fillColValue(ResultSet rs, VarBase varInto)
{
try
{
long lValue = rs.getLong(m_nColSourceIndex);
if (lValue != 0 || !rs.wasNull())
{
varInto.m_varDef.write(varInto.m_bufferPos, lValue);
return false;
}
}
catch (SQLException e)
{
LogSQLException.log(e);
// Maybe should I set m_bNull = true; ?
}
varInto.m_varDef.write(varInto.m_bufferPos, 0);
return true;
}
示例2: getValue
import java.sql.ResultSet; //导入方法依赖的package包/类
@Override
public OptionalInt getValue(final JavaType type, final ResultSet rs, final int columnIndex,
final PropertyMapperManager mapperManager) throws SQLException {
int value = rs.getInt(columnIndex);
if (!rs.wasNull()) {
return OptionalInt.of(value);
} else {
return OptionalInt.empty();
}
}
示例3: mapRow
import java.sql.ResultSet; //导入方法依赖的package包/类
@Override
public IBaseSegment mapRow(ResultSet rs, int rowNum) throws SQLException {
RoadDamageImpl rd = new RoadDamageImpl();
boolean valid = false;
try {
ColumnFinder colFinder = new ColumnFinder(rs);
if (colFinder.getColumnIndex(QUERY_PREFIX + "_segment_id") > -1) {
rd.setSegmentId(rs.getLong(QUERY_PREFIX + "_segment_id"));
if (!rs.wasNull()) {
valid = true;
}
}
if (colFinder.getColumnIndex(QUERY_PREFIX + "_direction_tow") > -1) {
rd.setDirectionTow(rs.getBoolean(QUERY_PREFIX + "_direction_tow"));
}
if (colFinder.getColumnIndex(QUERY_PREFIX + "_graphversion_id") > -1) {
rd.setGraphVersionId(rs.getLong(QUERY_PREFIX + "_graphversion_id"));
}
if (colFinder.getColumnIndex(QUERY_PREFIX + "_start_offset") > -1) {
rd.setStartOffset((float)rs.getDouble(QUERY_PREFIX + "_start_offset"));
}
if (colFinder.getColumnIndex(QUERY_PREFIX + "_end_offset") > -1) {
rd.setEndOffset((float)rs.getDouble(QUERY_PREFIX + "_end_offset"));
}
if (colFinder.getColumnIndex(QUERY_PREFIX + "_type") > -1) {
rd.setType(rs.getString(QUERY_PREFIX + "_type"));
}
} catch (SQLException e) {}
if (valid) {
IBaseSegment segment = new BaseSegment();
segment.setId(rd.getSegmentId());
segment.addXInfo(rd);
return segment;
} else {
return null;
}
}
示例4: getResult
import java.sql.ResultSet; //导入方法依赖的package包/类
public Object getResult(ResultSet rs, String columnName) throws SQLException {
Object sqlTime = rs.getTime(columnName);
if (rs.wasNull()) {
return null;
}
else {
return sqlTime;
}
}
示例5: transfer
import java.sql.ResultSet; //导入方法依赖的package包/类
public boolean transfer(int nColumnNumber1Based, ResultSet resultSetSource, PreparedStatement insertStatementInsert)
{
try
{
int nValue = resultSetSource.getInt(m_nColSourceIndex);
if (!resultSetSource.wasNull())
insertStatementInsert.setInt(m_nColSourceIndex, nValue);
else
insertStatementInsert.setNull(m_nColSourceIndex, Types.INTEGER);
return true;
}
catch (SQLException e)
{
e.printStackTrace();
}
return false;
}
示例6: testUnionColumnTypes
import java.sql.ResultSet; //导入方法依赖的package包/类
/**
* In 1.8.0.2, this fails in client / server due to column type of the
* second select for b1 being boolean, while the first select is interpreted
* as varchar. The rowOutputBase class attempts to cast the Java Boolean
* into String.
*/
public void testUnionColumnTypes() {
try {
Connection conn = newConnection();
Statement stmt = conn.createStatement();
stmt.execute("DROP TABLE test1 IF EXISTS");
stmt.execute("DROP TABLE test2 IF EXISTS");
stmt.execute("CREATE TABLE test1 (id int, b1 boolean)");
stmt.execute("CREATE TABLE test2 (id int)");
stmt.execute("INSERT INTO test1 VALUES(1,true)");
stmt.execute("INSERT INTO test2 VALUES(2)");
ResultSet rs = stmt.executeQuery(
"select id,null as b1 from test2 union select id, b1 from test1");
Boolean[] array = new Boolean[2];
for (int i = 0; rs.next(); i++) {
boolean boole = rs.getBoolean(2);
array[i] = Boolean.valueOf(boole);
if (rs.wasNull()) {
array[i] = null;
}
}
boolean result = (array[0] == null && array[1] == Boolean.TRUE)
|| (array[0] == Boolean.TRUE
&& array[1] == null);
assertTrue(result);
} catch (SQLException e) {
e.printStackTrace();
System.out.println("TestSql.testUnionColumnType() error: "
+ e.getMessage());
}
}
示例7: toJSON
import java.sql.ResultSet; //导入方法依赖的package包/类
public static JSONArray toJSON(ResultSet rs) throws SQLException, JSONException {
JSONArray json = new JSONArray();
ResultSetMetaData rsmd = rs.getMetaData();
int numColumns = rsmd.getColumnCount();
String column_name;
while (rs.next()) {
JSONObject obj = new JSONObject();
for (int i = 1; i < numColumns + 1; i++) {
column_name = rsmd.getColumnName(i);
String myValue = rs.getString(i);
if (!rs.wasNull()) {
if (rsmd.getColumnType(i) == java.sql.Types.CHAR) {
obj.put(column_name, rs.getString(i));
} else if (rsmd.getColumnType(i) == java.sql.Types.VARCHAR) {
obj.put(column_name, rs.getString(i));
} else if (rsmd.getColumnType(i) == java.sql.Types.LONGVARCHAR) {
obj.put(column_name, rs.getString(i));
} else if (rsmd.getColumnType(i) == java.sql.Types.BINARY) {
obj.put(column_name, rs.getBytes(i));
} else if (rsmd.getColumnType(i) == java.sql.Types.VARBINARY) {
obj.put(column_name, rs.getBytes(i));
} else if (rsmd.getColumnType(i) == java.sql.Types.LONGVARBINARY) {
obj.put(column_name, rs.getBinaryStream(i));
} else if (rsmd.getColumnType(i) == java.sql.Types.BIT) {
obj.put(column_name, rs.getBoolean(column_name));
} else if (rsmd.getColumnType(i) == java.sql.Types.TINYINT) {
obj.put(column_name, rs.getInt(column_name));
} else if (rsmd.getColumnType(i) == java.sql.Types.SMALLINT) {
obj.put(column_name, rs.getInt(i));
} else if (rsmd.getColumnType(i) == java.sql.Types.INTEGER) {
obj.put(column_name, rs.getInt(i));
} else if (rsmd.getColumnType(i) == java.sql.Types.BIGINT) {
obj.put(column_name, rs.getInt(i));
} else if (rsmd.getColumnType(i) == java.sql.Types.REAL) {
obj.put(column_name, rs.getFloat(i));
} else if (rsmd.getColumnType(i) == java.sql.Types.DOUBLE) {
obj.put(column_name, rs.getDouble(i));
} else if (rsmd.getColumnType(i) == java.sql.Types.FLOAT) {
obj.put(column_name, rs.getFloat(i));
} else if (rsmd.getColumnType(i) == java.sql.Types.DECIMAL) {
obj.put(column_name, rs.getBigDecimal(i).doubleValue());
} else if (rsmd.getColumnType(i) == java.sql.Types.NUMERIC) {
obj.put(column_name, rs.getBigDecimal(i).doubleValue());
} else if (rsmd.getColumnType(i) == java.sql.Types.DATE) {
obj.put(column_name, rs.getDate(i).toString());
} else if (rsmd.getColumnType(i) == java.sql.Types.TIME) {
obj.put(column_name, rs.getDate(i).toString());
} else if (rsmd.getColumnType(i) == java.sql.Types.TIMESTAMP) {
obj.put(column_name, rs.getTimestamp(i).toString());
} else if (rsmd.getColumnType(i) == java.sql.Types.ARRAY) {
obj.put(column_name, rs.getArray(i));
} else if (rsmd.getColumnType(i) == java.sql.Types.BOOLEAN) {
obj.put(column_name, rs.getBoolean(i));
} else if (rsmd.getColumnType(i) == java.sql.Types.BLOB) {
obj.put(column_name, rs.getBlob(i));
} else if (rsmd.getColumnType(i) == java.sql.Types.NVARCHAR) {
obj.put(column_name, rs.getNString(i));
} else {
obj.put(column_name, rs.getObject(i));
}
} else {
obj.put(column_name, JSONObject.NULL);
}
}
json.put(obj);
}
return json;
}
示例8: getIntOrNull
import java.sql.ResultSet; //导入方法依赖的package包/类
private Integer getIntOrNull( ResultSet row, String columnName ) throws SQLException {
final int value = row.getInt( columnName );
return row.wasNull() ? null : new Integer( value );
}
示例9: loadTransaction
import java.sql.ResultSet; //导入方法依赖的package包/类
static TransactionImpl loadTransaction(Connection con, ResultSet rs) throws NxtException.ValidationException {
try {
byte type = rs.getByte("type");
byte subtype = rs.getByte("subtype");
int timestamp = rs.getInt("timestamp");
short deadline = rs.getShort("deadline");
byte[] senderPublicKey = rs.getBytes("sender_public_key");
long amountNQT = rs.getLong("amount");
long feeNQT = rs.getLong("fee");
byte[] referencedTransactionFullHash = rs.getBytes("referenced_transaction_full_hash");
int ecBlockHeight = rs.getInt("ec_block_height");
long ecBlockId = rs.getLong("ec_block_id");
byte[] signature = rs.getBytes("signature");
long blockId = rs.getLong("block_id");
int height = rs.getInt("height");
long id = rs.getLong("id");
long senderId = rs.getLong("sender_id");
byte[] attachmentBytes = rs.getBytes("attachment_bytes");
int blockTimestamp = rs.getInt("block_timestamp");
byte[] fullHash = rs.getBytes("full_hash");
byte version = rs.getByte("version");
ByteBuffer buffer = null;
if (attachmentBytes != null) {
buffer = ByteBuffer.wrap(attachmentBytes);
buffer.order(ByteOrder.LITTLE_ENDIAN);
}
TransactionType transactionType = TransactionType.findTransactionType(type, subtype);
TransactionImpl.BuilderImpl builder = new TransactionImpl.BuilderImpl(version, senderPublicKey,
amountNQT, feeNQT, timestamp, deadline,
transactionType.parseAttachment(buffer, version))
.referencedTransactionFullHash(referencedTransactionFullHash)
.signature(signature)
.blockId(blockId)
.height(height)
.id(id)
.senderId(senderId)
.blockTimestamp(blockTimestamp)
.fullHash(fullHash);
if (transactionType.hasRecipient()) {
long recipientId = rs.getLong("recipient_id");
if (! rs.wasNull()) {
builder.recipientId(recipientId);
}
}
if (rs.getBoolean("has_message")) {
builder.message(new Appendix.Message(buffer, version));
}
if (rs.getBoolean("has_encrypted_message")) {
builder.encryptedMessage(new Appendix.EncryptedMessage(buffer, version));
}
if (rs.getBoolean("has_public_key_announcement")) {
builder.publicKeyAnnouncement(new Appendix.PublicKeyAnnouncement(buffer, version));
}
if (rs.getBoolean("has_encrypttoself_message")) {
builder.encryptToSelfMessage(new Appendix.EncryptToSelfMessage(buffer, version));
}
if (version > 0) {
builder.ecBlockHeight(ecBlockHeight);
builder.ecBlockId(ecBlockId);
}
return builder.build();
} catch (SQLException e) {
throw new RuntimeException(e.toString(), e);
}
}
示例10: getNullableResult
import java.sql.ResultSet; //导入方法依赖的package包/类
@Override
public Hours getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
int hours = rs.getInt(columnIndex);
return rs.wasNull() ? null : Hours.of(hours);
}
示例11: getNullableResult
import java.sql.ResultSet; //导入方法依赖的package包/类
@Override
public Years getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
int years = rs.getInt(columnIndex);
return rs.wasNull() ? null : Years.of(years);
}
示例12: getNullableResult
import java.sql.ResultSet; //导入方法依赖的package包/类
@Override
public Seconds getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
int seconds = rs.getInt(columnIndex);
return rs.wasNull() ? null : Seconds.of(seconds);
}
示例13: getAppObject
import java.sql.ResultSet; //导入方法依赖的package包/类
/** Gets a parameter from the ResultSet.
* @return the parameter.
* @param engineType The engine type as defined in init.xml
* @param rs The ResultSet.
* @param columnName The name of the parameter.
* @throws SQLException if a database access error occurs.
* @throws IOException if any error occurs in reading the data from the database.
*/
public Object getAppObject(ResultSet rs, String columnName, String engineType) throws SQLException, IOException {
long value = rs.getLong(columnName);
if (rs.wasNull())
return null;
else
return new Long(value);
}
示例14: getDouble
import java.sql.ResultSet; //导入方法依赖的package包/类
/**
* Returns the value from the result set at current row and col index specified
* @param rs the result set reference
* @param colIndex the result set column index
* @return the value extracted from result set
* @throws SQLException
*/
public double getDouble(ResultSet rs, int colIndex) throws SQLException {
final double value = rs.getDouble(colIndex);
return rs.wasNull() ? Double.NaN : value;
}