All pastes #79013 Raw Edit

Stuff

public java v1 · immutable
·published 2006-07-04 20:06 UTC
rendered paste body
    public static int store(InputStream in) throws SQLException,IOException {                Connection what = DbResource.getInstance().DbConnect();        Connection con = what.getMetaData().getConnection();        System.out.println("con class: "+con.getClass());                String sql = "INSERT INTO super_files (file_id, filedata) VALUES (super_files_seq.nextval, EMPTY_BLOB())";                Statement stmt = con.createStatement();                sql = "SELECT MAX(file_id) FROM super_files";        Statement stmt3 = con.createStatement();        ResultSet res2 = stmt3.executeQuery(sql);        int id = 0;        if (res2.next()) {            id = res2.getInt(1);        }        res2.close();        con.setAutoCommit(false);        sql = "SELECT file_id,filedata FROM super_files WHERE file_id = "+id+" for update";        //sql = "SELECT file_id FROM super_files";        Statement stmt2 = con.createStatement();        System.out.println("stmt2 class: "+stmt2.getClass());        stmt.close();        ResultSet oRS = stmt2.executeQuery(sql);        System.out.println("MOTHERFUCKING RESULT" + oRS.getClass());                int key = 0;        if (oRS.next()) {               /* line below is throwing: java.lang.ClassCastException: oracle.jdbc.driver.OracleResultSetImpl */               BLOB fileData = ((OracleResultSet)oRS).getBLOB("filedata");                           int bufferSize = fileData.getBufferSize();                byte buffer[] = new byte[bufferSize];                OutputStream os = fileData.getBinaryOutputStream();                int bytesRead = 0;                while ((bytesRead = in.read(buffer)) != -1) {                    os.write(buffer, 0, bytesRead);                    System.out.println("GRRRRRR");                }                in.close();                os.close();        }        stmt2.close();        con.commit();                return key;    }