本文介绍了从数据库中获取二进制数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
我正在编写代码以从数据库中获取二进制数据到字节数组中.我的代码段如下
Hi
i was writing a code to fetch binary data from database into a byte array.My code snippet is as follows
public byte[] getRecord(String query, String[] expValues) throws SQLException, Exception
{
//expvalues is the column names i pass while calling a function
byte tempResult =0 ;
byte[] result = null;
Connection con = openConnection();
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query);
int size = 0;
int i = 0;
// Loop through the result set
while (rs.next())
{
size++;
for (i = 0; i < expValues.length; i++)
{
result = rs.getBytes(1);
}
}
// Close the result set, statement and the connection
rs.close();
stmt.close();
con.close();
return result;
}
// eof getRecordSet
当我运行代码时,出现以下错误
when i run the code i get the following error
sqle java.sql.SQLException: Unable to convert between java.lang.Integer and BINARY.
Exception java.lang.NullPointerException
谁能帮助我解释为什么错误或如何从Java中的数据库中获取二进制数据?
anybody plz can help on why i am geeting the error OR how to fetch binary data from database in java?
推荐答案
这篇关于从数据库中获取二进制数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!