我是mulesoft和Java的新手,正在尝试将blob插入oracle。 它将引发错误“无效的列类型”。
下面是我来自mulesoft anypoint 7.3的代码。
package practice_api_design;
import java.io.UnsupportedEncodingException;
import java.sql.Blob;
import java.sql.SQLException;
import javax.sql.rowset.serial.SerialBlob;
import javax.sql.rowset.serial.SerialException;
public class Base64ToBlob {
public String b = "";
public Base64ToBlob(String base64Str) {
b = (String) base64Str;
}
public Blob byteArrToBlob(String b) throws SerialException, SQLException, UnsupportedEncodingException {
Blob blob = null;
byte[] byteArr = b.getBytes();
blob = new SerialBlob(byteArr);
return blob;
}
}
这是来自mulesoft的项目配置。
<flow name="uploadDocuments" doc:id="0a5e9e1d-a5d9-48af-959b-3c8292f3aff8" >
<http:listener doc:name="Upload documents" doc:id="ab922884-b2f4-4c49-a14a-8a6e48f26266" config-ref="Global_Listener" path="/uploadDocs"/>
<ee:transform doc:name="Transform Message" doc:id="70408165-9d05-412b-906a-bd1c8cb30df9" >
<ee:message >
<ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
[
{
name: payload.name,
mimeType: payload.mimeType,
dadCharset: payload.dadCharset,
contentType: payload.contentType,
base64Str: payload.base64Str,
description: payload.description,
username: payload.username
}
]]]></ee:set-payload>
</ee:message>
</ee:transform>
<set-variable value="#[{
name: payload[0].name[0],
mimeType: payload[0].mimeType[0],
dadCharset: payload[0].dadCharset[0],
contentType: payload[0].contentType[0],
base64Str: payload[0].base64Str[0],
description: payload[0].description[0],
username: payload[0].username[0]
}]" doc:name="Set Variable" doc:id="1ee41214-5534-4f71-ad43-41c3e0a96817" variableName="jsonObj"/>
<java:new constructor="Base64ToBlob(java.lang.String)" doc:name="New" doc:id="4f1400d5-c453-43e8-beb3-1b3a8191f208" class="practice_api_design.Base64ToBlob">
<java:args ><![CDATA[#[{
base64Str: payload[0].base64Str[0]
}]]]></java:args>
</java:new>
<java:invoke method="byteArrToBlob(java.lang.String)" doc:name="Invoke" doc:id="88592758-6fe1-4f09-a56e-dfc57760111f" instance="#[payload]" class="practice_api_design.Base64ToBlob" target="blob">
<java:args ><![CDATA[#[{
b: vars.jsonObj.base64Str
}]]]></java:args>
</java:invoke>
<db:insert doc:name="Insert" doc:id="f1b53033-7dda-49f8-ae70-81b0b2e72607" config-ref="ELS_Blue">
<db:sql >insert into
app_wag.stdprosp_files
(
name,
blob_content
)
values
(
:name,
:blob
)</db:sql>
<db:input-parameters ><![CDATA[#[{
name: vars.jsonObj.name,
blob: vars.blob
}]]]></db:input-parameters>
</db:insert>
<logger level="INFO" doc:name="Logger" doc:id="6068e02b-6c29-44f5-af76-849652a2f7ae" message="#[vars.blob]" />
</flow>
并在插入时抛出。.
Invalid column type
检查了oracle并确认该列的数据类型为'BLOB',我认为它会接受任何类型为BLOB的值。
对此有任何想法或想法吗?