Results 1 to 2 of 2
  1. #1
    kodjeff1 is offline Member
    Join Date
    Apr 2011
    Rep Power

    Default Error retrieving serialized data from database

    Hello all,

    I am trying to write a Vector of String's to my database, my write code seems to be working correctly (no exceptions being thrown):

    Vector<String> vector = new Vector<String>();
    try {
    String insertionString = "INSERT INTO test SET testField = ?";
    PreparedStatement ps = dbConn.prepareStatement(insertionString);
    ps.setObject(1, vector);
    System.out.println("Insert successful");
    } catch (SQLException e) {


    However, when I try to read the data back out, I am getting many errors:

    java.sql.SQLException: Before start of result set
    at com.mysql.jdbc.SQLError.createSQLException(SQLErro
    at com.mysql.jdbc.SQLError.createSQLException(SQLErro
    at com.mysql.jdbc.SQLError.createSQLException(SQLErro
    at com.mysql.jdbc.SQLError.createSQLException(SQLErro
    at com.mysql.jdbc.ResultSetImpl.checkRowPos(ResultSet
    at com.mysql.jdbc.ResultSetImpl.getObject(ResultSetIm
    at Main.init(
    at Source)
    at Source)

    My read code is as follows:
    Statement st;
    try {
    st = dbConn.createStatement();
    ResultSet rs = st.executeQuery("SELECT * FROM test");
    Object obj = rs.getObject(1);
    } catch (SQLException e) {
    // TODO Auto-generated catch block

    As I understand it, setObject and getObject should take care of all serialization (allowing me to avoid all the streaming mess).

    My database only has one column, and one row. The column type is BLOB.

    Does anyone see the problem?

  2. #2
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Rep Power


    A ResultSet is initially pointing before the first record (as the error says), so you have to use next() to get it to point to the first record.

    As to your general setObject() has nothing to do with serialisation. You will need to use the object stream and setBinaryStream() to serialise it.

Similar Threads

  1. Retrieving data from database every 10 secs.
    By vnsuresh.abi in forum JavaServer Pages (JSP) and JSTL
    Replies: 4
    Last Post: 03-31-2011, 11:14 AM
  2. error in reading data from table in pidgree database
    By chethan_kc in forum Java Servlet
    Replies: 17
    Last Post: 02-18-2011, 03:11 PM
  3. Replies: 1
    Last Post: 03-19-2009, 08:38 AM
  4. error while retrieving data from data base
    By kirtesh4u in forum New To Java
    Replies: 5
    Last Post: 11-15-2008, 05:10 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts