我尝试在oracle数据库中运行此查询但不幸的是我收到此错误请帮助我:(
java.sql.SQLException:ORA-01460:请求未实现或不合理的转换 现在问题解决了,我有另一个例外: 我改变了这一行
pstmt.setBinaryStream(7, fis, (int) file.length());
与
pstmt.setBinaryStream(7, fis, (long) file.length());
线程“AWT-EventQueue-0”中的异常java.lang.AbstractMethodError:oracle.jdbc.driver.OraclePreparedStatement.setBinaryStream(ILjava / io / InputStream; J)V
对于文本文件没有问题,但是当我尝试上传JPG文件时,我收到此错误。
PreparedStatement pstmt =
conn.prepareStatement("INSERT INTO PM_OBJECT_TABLE( " +
"N_ACTIVITY_ID, V_NAME,N_SIZE, D_MODIFY,N_CATEGORY, N_NODE_ID ,O_OBJECT) " +
" VALUES ( ? , ? , ? , ? , ? , ? ,?)");
pstmt.setLong(1, N_ACTIVITY_ID);
pstmt.setString(2, file.getName());
pstmt.setLong(3, file.length());
java.util.Date date = new java.util.Date();
java.sql.Date sqlDate = new java.sql.Date(date.getTime());
pstmt.setDate(4,sqlDate);
pstmt.setInt(5, N_CATEGORY);
pstmt.setLong(6, N_NODE_ID);
pstmt.setBinaryStream(7, fis, (int) file.length());
pstmt.executeUpdate();
答案 0 :(得分:1)
java.lang.AbstractMethodError:com.mysql.jdbc.ServerPreparedStatement.setBinaryStream(ILjava / io / InputStream; J)V
要解决此问题,您需要更改对setBinaryStream的调用,以便将最后一个参数作为整数而不是long传递。
我在面对同样的问题时在博客中找到了引用
就像上面的PreparedStatement.setBinaryStream()有三个重载方法
我们应该使用setBinaryStream(columnIndex,InputStream,(((((((((INT))))))))
否则,可能会导致错误
答案 1 :(得分:1)
我也遇到过这个问题,代码正常工作,然后突然出现了这个错误。
我正在使用Glassfish 3运行Netbeans 8.0.2 在GlassFish \ Glassfish \ libs文件夹中,我有2个ojdbc文件ojdbc6.jar和ojdbc14.jar 似乎即使ojdbc6被包含在项目库中,ojdbc14也被加载了。
我停止将glassfish重命名为ojdbc14.jar到ojdbc14.jar.bak,然后清理并构建和部署项目。
问题已解决。
答案 2 :(得分:0)
我通过之前的建议解决了我的问题:
public String insertBineryToDB(long N_ACTIVITY_ID,int N_CATEGORY,long N_NODE_ID ,FileInputStream fis , java.io.File file) {
Statement statement;
try {
//conn.close();
// N_ACTIVITY_ID, V_NAME,N_SIZE, D_MODIFY,N_CATEGORY, N_NODE_ID ,O_OBJECT
PreparedStatement pstmt =
conn.prepareStatement("INSERT INTO PM_OBJECT_TABLE( " +
"N_ACTIVITY_ID, V_NAME,N_SIZE, D_MODIFY,N_CATEGORY, N_NODE_ID ,O_OBJECT) " +
" VALUES ( ? , ? , ? , ? , ? , ? ,empty_blob())");
InputStream bodyIn = fis;
pstmt.setLong(1, N_ACTIVITY_ID);
pstmt.setString(2, file.getName());
pstmt.setLong(3, file.length());
java.util.Date date = new java.util.Date();
java.sql.Date sqlDate = new java.sql.Date(date.getTime());
pstmt.setDate(4,sqlDate);
pstmt.setInt(5, N_CATEGORY);
pstmt.setLong(6, N_NODE_ID);
//pstmt.setBinaryStream(7, bodyIn,(int) file.length());
pstmt.executeUpdate();
conn.commit();
PreparedStatement stmt2 = conn.prepareStatement(" select O_OBJECT from PM_OBJECT_TABLE where N_ACTIVITY_ID = ? for update ");
stmt2.setLong(1, N_ACTIVITY_ID);
ResultSet rset = stmt2.executeQuery();
FileInputStream inputFileInputStream = new FileInputStream(file);
rset.next();
BLOB image = ((OracleResultSet) rset).getBLOB("O_OBJECT");
int bufferSize;
byte[] byteBuffer;
int bytesRead = 0;
int bytesWritten = 0;
int totBytesRead = 0;
int totBytesWritten = 0;
bufferSize = image.getBufferSize();
byteBuffer = new byte[bufferSize];
OutputStream blobOutputStream = image.getBinaryOutputStream();
while ((bytesRead = inputFileInputStream.read(byteBuffer)) != -1) {
// After reading a buffer from the binary file, write the contents
// of the buffer to the output stream using the write()
// method.
blobOutputStream.write(byteBuffer, 0, bytesRead);
totBytesRead += bytesRead;
totBytesWritten += bytesRead;
}
inputFileInputStream.close();
blobOutputStream.close();
conn.commit();
rset.close();
stmt2.close();
String output = "Wrote file " + file.getName() + " to BLOB column." +
totBytesRead + " bytes read." +
totBytesWritten + " bytes written.\n";
return output;
} catch (Exception e) {
e.printStackTrace();
return "Wrote file " + file.getName() + " to BLOB column failed." ;
}
}
答案 3 :(得分:0)
使用java.sql.PreparedStatement.setBinaryStream(int parameterIndex,InputStream x) - 2个参数,而不是3个。