lixuemao
lixuemao
采纳率0%
2015-12-08 07:14 阅读 11.6k

java 如何保存、读取数据库字段为blob类型的值

java 如何保存、读取javaBean中定义String类型,oracle数据库字段为blob类型的值

这是我的业务逻辑代码
try {
String encoding = "GBK";
File file = new File("E:\workspaceNeuSoft\tomcat7.0.40\logs\localhost.2015-12-07.log");
if (file.isFile() && file.exists()) { // 判断文件是否存在
InputStreamReader read = new InputStreamReader(
new FileInputStream(file), encoding);// 考虑到编码格式
BufferedReader bufferedReader = new BufferedReader(read);
String lineTxt = null;
while ((lineTxt = bufferedReader.readLine()) != null) {
// System.out.println(lineTxt);
interfaceLog.setFwqIp(ip);
interfaceLog.setJkLog(lineTxt);
interfaceLogService.createInterfaceLog(interfaceLog);
}
read.close();
} else {
System.out.println("找不到指定的文件");
}
} catch (Exception e) {
System.out.println("读取文件内容出错");
e.printStackTrace();
}

这个是mybatis中代码


SELECT seq_neu_interfacelog_id.NEXTVAL FROM DUAL


<![CDATA[
INSERT INTO neu_interfacelog DS
(DS.ROW_ID,
DS.CREATE_BY,
DS.CREATE_DATE,
DS.REMARK,
DS.FWQ_IP,
DS.INTERFACELOG
)
VALUES
(#{rowId},
#{createBy},
SYSDATE,
#{remark},
#{fwqIp},
#{jkLog})

    ]]> 
</insert>


现在控制台报异常
015-12-08 15:00:00,620 INFO  org.quartz.plugins.history.LoggingTriggerHistoryPlugin.triggerComplete:432 - Trigger neuSoftWorkPlatform_TRIGGER_GROUP.interfaceLogExpireBean completed firing job neuSoftWorkPlatform_JOB_GROUP.interfaceLogExpire at  15:00:00 12/08/2015 with resulting trigger instruction code: DO NOTHING

org.springframework.jdbc.UncategorizedSQLException:

Error updating database. Cause: java.sql.SQLException: ORA-01465: 无效的十六进制数字

The error may exist in file [E:\workspaceNeuSoft\neuSoftWorkPlatform\neuSoftWorkPlatform-biz\target\classes\mybatis\mappers\interfaceLog\InterfaceLogMapper.xml]

The error may involve com.neusoft.interfaceLog.dao.InterfaceLogDAO.save-Inline

The error occurred while setting parameters

SQL: INSERT INTO neu_interfacelog DS (DS.ROW_ID, DS.CREATE_BY, DS.CREATE_DATE, DS.REMARK, DS.FWQ_IP, DS.INTERFACELOG ) VALUES (?, ?, SYSDATE, ?, ?, ?)

Cause: java.sql.SQLException: ORA-01465: 无效的十六进制数字

; uncategorized SQLException for SQL []; SQL state [72000]; error code [1465]; ORA-01465: 无效的十六进制数字
; nested exception is java.sql.SQLException: ORA-01465: 无效的十六进制数字

at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:83)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:71)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:365)
at com.sun.proxy.$Proxy27.insert(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate.insert(SqlSessionTemplate.java:237)
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:79)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:40)
at com.sun.proxy.$Proxy86.save(Unknown Source)
at com.neusoft.interfaceLog.service.impl.InterfaceLogServiceImpl.createInterfaceLog(InterfaceLogServiceImpl.java:60)
at com.haier.openplatform.showcase.quartz.InterfaceLogExpireJob.execute(InterfaceLogExpireJob.java:52)
at org.quartz.core.JobRunShell.run(JobRunShell.java:213)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:557)

Caused by: java.sql.SQLException: ORA-01465: 无效的十六进制数字

at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288)
at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:743)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:216)
at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:955)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1168)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3285)
at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:3390)
at com.haier.openplatform.jdbc.HOPPraparedStatement$3.run(HOPPraparedStatement.java:183)
at com.haier.openplatform.jdbc.HOPPraparedStatement$3.run(HOPPraparedStatement.java:180)
at com.haier.openplatform.jdbc.HOPPraparedStatement.doProfile(HOPPraparedStatement.java:382)
at com.haier.openplatform.jdbc.HOPPraparedStatement.execute(HOPPraparedStatement.java:180)
at org.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:41)
at org.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:66)
at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:45)
at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:108)
at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:75)
at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:145)
at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:134)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:355)
... 9 more
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

2条回答 默认 最新

  • mjcays sole.mjc 2018-06-22 02:30

    java中如何接收一个 十六进制的数据 并保存到数据库中,数据库中字段类型longbolb,如何读取

    点赞 评论 复制链接分享
  • qq_32650649 qq_32650649 2018-11-21 06:24

    我这里可以提供一个我刚刚使用过的方案,先把需要存储的图片转为base64编码的字符串,再将此字符串转化为byte[],然后就可以在数据库中用blob字段进行存储了。
    比如我这里:
    byte[] contextBytes = communityPO.getContentTxt().getBytes();
    communityPO.setContentTxtBytes(contextBytes);
    数据库中就直接存储这个contextBytes就可以了。
    对应的mybatis文件中result中可以这样写:
    result column="content_txt" typeHandler="org.apache.ibatis.type.BlobTypeHandler" property="contentTxtBytes"

    点赞 评论 复制链接分享

相关推荐