java 如何仅使用java程序将字符串转换为字节数组并将字节数组转换为Blob
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13320552/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 12:17:19 来源:igfitidea点击:
how to Convert String to byte array and byte array to Blob using only java program
提问by Satish Dhiman
Question is:
问题是:
String strContent = "Hello Hi How are you ";
byte[] byteConent = strContent.getBytes();
But further I want convert to Blob only in Java program
但进一步我只想在 Java 程序中转换为 Blob
Because I m working on some script for MySQL DB by default for our application.
因为我正在为我们的应用程序默认为 MySQL DB 编写一些脚本。
Regards, Satish
问候, 萨蒂什
回答by Mukul Goel
Blob blob = connection.createBlob();
blob.setBytes(1, bytes);
Where connection is the connection to db object.
其中 connection 是与 db 对象的连接。
回答by Saddam Abu Ghaida
Blob blob=null;
blob=new SerialBlob(byteContent);