您可以将字节数组转换为blob,而无需将字节数组转换为SerialBlob类的构造函数。
import java.io.BufferedReader; import java.io.FileReader; import java.sql.Blob; import java.util.Scanner; import javax.sql.rowset.serial.SerialBlob; public class ByteArrayToBlob { public static void main(String args[]) throws Exception { Scanner sc = new Scanner(new BufferedReader(new FileReader("myData"))); Blob blob = null; while(sc.hasNext()) { byte[] myArray = sc.nextLine().getBytes(); blob = new SerialBlob(myArray ); } } }