Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何将blob从db转换为列表<;对象>;在爪哇_Java_Java 8 - Fatal编程技术网

Java 如何将blob从db转换为列表<;对象>;在爪哇

Java 如何将blob从db转换为列表<;对象>;在爪哇,java,java-8,Java,Java 8,我所要做的就是将java列表转换为BLOB,反之亦然。我已经成功地完成了第一部分,在那里我转换了我的列表并将其作为BLOB存储在DB中。但是,我无法获取BLOB,但无法将其转换回列表。我尝试过在很多地方搜索,但没有找到解决我面临的这个问题的方法。希望我能在这里找到解决办法 转换列表并将其存储为数据库中的BLOB: 我在这里迷路了,因为我不知道如何将List转换为List 期待你的帮助。。蒂亚 我对您的第一次尝试稍作修改如下: Blob blob = rs.getBlob("CUSTOMERS_L

我所要做的就是将java列表转换为BLOB,反之亦然。我已经成功地完成了第一部分,在那里我转换了我的列表并将其作为BLOB存储在DB中。但是,我无法获取BLOB,但无法将其转换回列表。我尝试过在很多地方搜索,但没有找到解决我面临的这个问题的方法。希望我能在这里找到解决办法

转换列表并将其存储为数据库中的BLOB: 我在这里迷路了,因为我不知道如何将
List
转换为
List


期待你的帮助。。蒂亚

我对您的第一次尝试稍作修改如下:

Blob blob = rs.getBlob("CUSTOMERS_LIST");   
byte[] bdata = blob.getBytes(1, (int) blob.length());
ArrayList<Object> arraylist = new ArrayList<>();
for(byte b : bdata) {
    arraylist.add(new Byte(b));
}
Blob Blob=rs.getBlob(“客户列表”);
byte[]bdata=blob.getBytes(1,(int)blob.length());
ArrayList ArrayList=新的ArrayList();
for(字节b:bdata){
add(新字节(b));
}

那么您基本上是在序列化列表并使用java序列化对其进行反序列化?我也不知道您使用的是哪个
Blob
,但为什么您要从第一个字节而不是从零字节读取
blob.getBytes(1,(int)blob.length())
@Eugene No,我在这里显示的代码就是我的全部tried@Eugenejava.sql.Blob it isDid您是否在CustomerDTO类中实现了Serializable?执行了相同的操作,但在选中
arraylist>>[-84, -19, 0, 5, 115, 114, 0, 19, 106, 97, 118, 97, 46, 117, 116, 105, 108, 46, 65, 114, 114, 97, 121, 76, 105, 115, 116, 120, -127, -46, 29, -103, -57, 97, -99, 3, 0, 1, 73, 0, 4, 115, 105, 122, 101, 120, 112, 0, 0, 0, 0, 119, 4, 0, 0, 0, 0, 120]
另外,我如何将
arraylist
更改为
List
?@mannedear而不是arraylist arraylist=new arraylist();使用List arraylist=new arraylist();当我试图将
List
转换为
List
时抛出编译错误,因此我以这种方式更改了代码(字节b:bdata){arraylist.add(新字节(b),null);}但它给我带来了一个错误
java.lang.IndexOutfBoundsException:Index:-84,Size:0
上面的数组列表是需要转换为各自类型的字节数组。例如,如果需要将字节数组转换回pdf格式的原始文件,则使用FileOutputStream类。
Blob blob = rs.getBlob("CUSTOMERS_LIST");   
byte[] bdata = blob.getBytes(1, (int) blob.length());
ByteArrayInputStream bais = new ByteArrayInputStream(bdata);
ObjectInputStream ois = new ObjectInputStream(bais);

List<CustomerDTO> list = (ArrayList<CustomerDTO>) ois.readObject();
Stream<T> stream = (Stream<T>) rs.getBinaryStream("CUSTOMERS_LIST");
List<CustomerDTO> list = (List<CustomerDTO>) stream.collect(Collectors.toList());
IntStream bais = (IntStream) rs.getBinaryStream("CUSTOMERS_LIST");
Stream<Integer> stream = (Stream<Integer>) bais.boxed().collect(Collectors.toList());
List<Integer> ll = (List<Integer>)stream.collect(Collectors.toList());
Blob blob = rs.getBlob("CUSTOMERS_LIST");   
byte[] bdata = blob.getBytes(1, (int) blob.length());
ArrayList<Object> arraylist = new ArrayList<>();
for(byte b : bdata) {
    arraylist.add(new Byte(b));
}