我认为dedalo面临的问题是他正在处理数组(我假设一个是锯齿状的,一个是多维的),并且他想将这些数据序列化为blob。
但是,数组不是直接可序列化的,所以他问如何去做这件事。
去它会遍历数组,并建立一个字符串作为戴夫建议和存储字符串的最简单方法。正如duffymo指出的那样,这将允许您从数据库中的值中查看内容,而不是在需要时将数据反序列化。
如果您想知道如何将数组序列化为BLOB ...(这似乎只是矫枉过正)
你能够serialize one-dimensional arrays和jagged arrays,如:
public class Test {
public static void main(String[] args) throws Exception {
// Serialize an int[]
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("test.ser"));
out.writeObject(new int[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9});
out.flush();
out.close();
// Deserialize the int[]
ObjectInputStream in = new ObjectInputStream(new FileInputStream("test.ser"));
int[] array = (int[]) in.readObject();
in.close();
// Print out contents of deserialized int[]
System.out.println("It is " + (array instanceof Serializable) + " that int[] implements Serializable");
System.out.print("Deserialized array: " + array[0]);
for (int i=1; i<array.length; i++) {
System.out.print(", " + array[i]);
}
System.out.println();
}
}
至于什么数据类型来存储它作为MySQL中,there are only four blob types to choose from:
The four BLOB types are TINYBLOB, BLOB, MEDIUMBLOB, and LONGBLOB
选择满足e最好的取决于序列化对象的大小。我想像BLOB
会很好。
我只需要存储。此时此信息存储在2个.txt文件中。当我需要阅读这些文件时,我总是需要阅读所有的值。我只是想知道如何使用MySQL而不是使用文本文件。感谢您的信息 – dedalo 2010-04-17 13:08:15