Package java.sql

Examples of java.sql.Clob


            fromFile = new byte[1024];
            Statement s = conn.createStatement();
            s.execute("create table clobtable3(n int)");
            s.execute("alter table clobtable3 add column clobCol CLOB(1M)");
            s.close();
            Clob clob = buildAndInsertClobValue(0000,"short.txt",conn);
            Clob clob1 = buildAndInsertClobValue(1000, "aclob.txt",conn);
            Clob clob2 = buildAndInsertClobValue(2000,"littleclob.txt",conn);
            PreparedStatement ps3 = conn.prepareStatement("select * from " +
                    "clobtable3 where n=1000");
            ResultSet rs3 = ps3.executeQuery();
            rs3.next();
            Clob clob3 = rs3.getClob(2);
            if(!compareClob(clob1,clob3)) {
                System.out.println("Difference between the inserted and the " +
                        "queried Clob values");
            }
            PreparedStatement ps4 = conn.prepareStatement("select * from " +
                    "clobtable3");
            ResultSet rs4 = ps4.executeQuery();
            rs4.next();
            Clob clob4 = rs4.getClob(2);
            if(!compareClob(clob,clob4)) {
                System.out.println("Difference between the inserted and the " +
                        "queried Clob values");
            }
            rs4.next();
View Full Code Here


    void t_Clob_setMethods_Embedded(Connection conn){
        try {
            Statement s = conn.createStatement();
            ResultSet rs = s.executeQuery("select * from clobtable3");
            rs.next();
            Clob clob = rs.getClob(2);
            PreparedStatement ps = conn.prepareStatement("insert into clobtable3" +
                    " values(?,?)");
            ps.setInt(1, 3000);
            ps.setClob(2, clob);
            ps.executeUpdate();
View Full Code Here

     * Set the value from an non-null Java.sql.Clob object.
     */
    final void setObject(Object theValue)
        throws StandardException
    {
        Clob vc = (Clob) theValue;
       
        try {
            long vcl = vc.length();
            if (vcl < 0L || vcl > Integer.MAX_VALUE)
                throw this.outOfRange();
           
            setValue(new ReaderToUTF8Stream(vc.getCharacterStream(),
                    (int) vcl, 0, TypeId.CLOB_NAME), (int) vcl);
           
        } catch (SQLException e) {
            throw dataTypeConversion("DAN-438-tmp");
       }
View Full Code Here

            conn.commit();

      rs = stmt.executeQuery("select a from testUnicode2");
            while (rs.next())
            {
                Clob clob = rs.getClob(1);
                System.out.println("Length of clob is " + clob.length());
                Reader r = clob.getCharacterStream();
                char[] buf = new char[3];
                for (int i = 0; i < numStrings; i++)
                {
                    r.read(buf);
                    if (unicodeStrings[i].equals(new String(buf)))
View Full Code Here

        {
      stmt = conn.createStatement();
      rs = stmt.executeQuery("select a,b from testCLOB_MAIN");
      byte[] buff = new byte[128];
      // fetch row back, get the column as a clob.
            Clob clob;
            int clobLength, i = 0;
      while (rs.next()) {
                i++;
        // get the first column in select as a clob
                clob = rs.getClob(1);
                if (clob == null)
                    continue;
        InputStream fin = clob.getAsciiStream();
        int columnSize = 0;
        for (;;) {
          int size = fin.read(buff);
          if (size == -1)
            break;
          columnSize += size;
        }
                clobLength = rs.getInt(2);

                if (columnSize != clobLength)
          System.out.println("test failed, columnSize should be " + clobLength
             + ", but it is " + columnSize + ", i = " + i);
                if (columnSize != clob.length())
        {
          System.out.println("test failed, clob.length() should be " +  columnSize
             + ", but it is " + clob.length() + ", i = " + i);
        }
      }
      rs.close();
            conn.commit();
            System.out.println("clobTest0 finished");
View Full Code Here

    public String getClobString(ResultSet rs, int column)
        throws SQLException {
        if (useGetStringForClobs)
            return rs.getString(column);

        Clob clob = getClob(rs, column);
        if (clob == null)
            return null;
        if (clob.length() == 0)
            return "";

        // unlikely that we'll have strings over Integer.MAX_VALUE chars
        return clob.getSubString(1, (int) clob.length());
    }
View Full Code Here

                ResultSet.CONCUR_UPDATABLE);
            res = stmnt.executeQuery();
            if (!res.next()) {
                throw new InternalException(_loc.get("stream-exception"));
            }
            Clob clob = res.getClob(1);
            Writer writer = clob.setCharacterStream(1);
            copy(reader, writer);
            writer.close();
            res.updateClob(1, clob);
            res.updateRow();
View Full Code Here

    public String getClobString(ResultSet rs, int column)
        throws SQLException {
        if (_driverBehavior != BEHAVE_ORACLE)
            return super.getClobString(rs, column);

        Clob clob = getClob(rs, column);
        if (clob == null)
            return null;
        if (clob.getClass().getName().equals("oracle.sql.CLOB")) {
            try {
                if (((Boolean) Class.forName("oracle.sql.CLOB").
                    getMethod("isEmptyLob", new Class[0]).
                    invoke(clob, new Object[0])).
                    booleanValue())
                    return null;
            } catch (Exception e) {
                // possibly different version of the driver
            }
        }
        if (clob.length() == 0)
            return null;

        // unlikely that we'll have strings over 4 billion chars
        return clob.getSubString(1, (int) clob.length());
    }
View Full Code Here

        return readStringLob(reader);
    }
   
    public String getStringClob() throws SQLException {

        Clob clob = rset.getClob(pos());
        if (clob == null) {
            return null;
        }
        Reader reader = clob.getCharacterStream();
        if (reader == null) {
            return null;
        }
        return readStringLob(reader);
    }
View Full Code Here

    if ( value == null ) {
      st.setNull( index, Types.CLOB );
      return;
    }

    Clob clob = ( Clob ) value;

    if ( WrappedClob.class.isInstance( clob ) ) {
      clob = ( (WrappedClob) value ).getWrappedClob();
    }

    final boolean useInputStream = session.getFactory().getDialect().useInputStreamToInsertBlob()
        && ClobImplementer.class.isInstance( clob );

    if ( useInputStream ) {
      st.setCharacterStream( index, clob.getCharacterStream(), (int) clob.length() );
    }
    else {
      st.setClob( index, clob );
    }
  }
View Full Code Here

TOP

Related Classes of java.sql.Clob

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.