gpt4 book ai didi

java - 如何在java中检查getBytes(coloulm name)是否包含空值

转载 作者:行者123 更新时间:2023-12-01 21:28:20 33 4
gpt4 key购买 nike

我想检查以下语句是否为空

byte[] imageBytes = rs.getBytes("doctimg");

我的代码是......

while(rs.next() ) {
JsonObject row = new JsonObject();

/*Want to Check this
byte[] imageBytes = rs.getBytes("doctimg");
null or not*/
byte[] imageBytes = rs.getBytes("doctimg");
String imageBase64 = DatatypeConverter.printBase64Binary(imageBytes);

row.add("doctId",new JsonPrimitive(""+rs.getString("doctId")));
row.add("deptId",new JsonPrimitive(""+rs.getString("deptId")));


row.addProperty("img", imageBase64);

data.add(row);
}

最佳答案

您可以使用wasNull()方法:

byte[] imageBytes = rs.getBytes("doctimg");
if (rs.wasNull()) {
System.out.println("It was null!"); // or some more robust treatment
} else {
// Wasn't null, let's use it
String imageBase64 = DatatypeConverter.printBase64Binary(imageBytes);
}

关于java - 如何在java中检查getBytes(coloulm name)是否包含空值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37742643/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com