从数据库中获取二进制数据 [英] Fetching binary data from database

查看:104
本文介绍了从数据库中获取二进制数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在编写代码以从数据库中获取二进制数据到字节数组中.我的代码段如下

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?

推荐答案

您在上面的代码中有一些未声明的内容. SQL查询的内容是什么?从executeQuery()调用返回的结果是什么?
You have some undeclared items in the above code. What is the content of your SQL query and what results do you get returned from the executeQuery() call?


这篇关于从数据库中获取二进制数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆