我需要处理返回三个数据库(Oracle,sybase,MS-Server)的存储过程/函数的结果集.程序/功能通常是相同的,但在Oracle中调用稍有不同.
statement.registerOutParameter(1, oracle.jdbc.OracleTypes.CURSOR);
...
statement.execute();
ResultSet rs = (ResultSet)statement.getObject(1);
Run Code Online (Sandbox Code Playgroud)
JDBC没有提供处理它的通用方法,因此我需要在代码中区分不同类型的DB.我得到了连接,但不知道确定数据库是否为oracle的最佳方法.我可以使用驱动程序名称,但宁愿找到更清洁的方式.
我们在Oracle中有一个表,其中BLOB列需要填充少量任意字节数据 - 我们永远不会输入超过4000字节的数据.
我正在使用现有的基于C++ OCI的基础结构,这使得在某些上下文中使用绑定变量非常困难,因此我需要仅使用简单查询来填充此BLOB列.(我们正在努力使其现代化,但今天不是一种选择,)
我们对这样的查询运气不错:
UPDATE MyTable
SET blobData = HEXTORAW('0EC1D7FA6B411DA5814...lots of hex data...0EC1D7FA6B411DA5814')
WHERE ID = 123;
Run Code Online (Sandbox Code Playgroud)
起初,这很有效.但是,最近我们遇到了一个需要输入2000多字节数据的情况.此时,我们遇到了Oracle错误,ORA-01704: string literal too long因为传递给的字符串HEXTORAW超过了4000个字符.我尝试拆分字符串然后连接||,但这并没有避免错误.
因此,我需要一种更新此列的方法,并使用简单的查询将其填充超过2000字节的数据.可能吗?
(我知道如果我拥有绑定变量,那将是微不足道的 - 实际上与该表交互的其他应用程序使用这种确切的技术 - 但不幸的是我无法在这里重构数据库内容.只需要将数据输入表格.)
编辑:
一种没有用的有希望的方法是连接RAW:
UTL_RAW.CONCAT(HEXTORAW('...'), HEXTORAW('...'), HEXTORAW('...'))
Run Code Online (Sandbox Code Playgroud)
这避免了字符串长度限制,但似乎Oracle在a的长度上也有一个匹配的内部2000字节限制RAW.所以我不能用一个填充blob RAW.也许有一个函数可以将多个RAWs 连接成一个BLOB.
I have a SpringBoot app, where I use jdbcTemplate to insert a row to a mssql
int numOfRowsAffected = remoteJdbcTemplate.update("insert into dbo.[ELCOR Resource Time Registr_] "
+ "( [Entry No_], [Record ID], [Posting Date], [Resource No_], [Job No_], [Work Type], [Quantity], [Unit of Measure], [Description], [Company Name], [Created Date-Time], [Status] ) "
+ " VALUES (?,CONVERT(varbinary,?),?,?,?,?,?,?,?,?,?,?);",
ELCORResourceTimeRegistr.getEntryNo(),
ELCORResourceTimeRegistr.getEntryNo()),
ELCORResourceTimeRegistr.getPostingDate(),
ELCORResourceTimeRegistr.getResourceNo(),
jobNo,
ELCORResourceTimeRegistr.getWorkType(),
ELCORResourceTimeRegistr.getQuantity(),
ELCORResourceTimeRegistr.getUnitOfMeasure(),
ELCORResourceTimeRegistr.getDescription(),
ELCORResourceTimeRegistr.getCompanyName(),
ELCORResourceTimeRegistr.getCreatedDate(),
0);
Run Code Online (Sandbox Code Playgroud)
the value of ELCORResourceTimeRegistr.getEntryNo() is a String with the value 0x00173672
but …
jdbc ×2
oracle ×2
blob ×1
java ×1
jdbctemplate ×1
mssql-jdbc ×1
spring-jdbc ×1
sql ×1
sql-server ×1
varbinary ×1