Click here to Skip to main content
15,893,266 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
i was writing a code to fetch binary data from database into a byte array.My code snippet is as follows

Java
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




anybody plz can help on why i am geeting the error OR how to fetch binary data from database in java?
Posted
Updated 25-Sep-11 23:49pm
v2
Comments
Al Moje 26-Sep-11 5:56am    
Hi,

are you saying that you are fetching a binary field(s) like image type field(s) in a record in you database file?

1 solution

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?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900