Package java.sql

Examples of java.sql.NClob


      props1.put("characterEncoding", "latin1"); // ensure charset isn't utf8 here
      Connection conn1 = getConnectionWithProps(props1);
      PreparedStatement pstmt1 =
          conn1.prepareStatement("INSERT INTO testSetNClob (c1, c2, c3) VALUES (?, ?, ?)");
      pstmt1.setNClob(1, (NClob)null);
      NClob nclob2 = conn1.createNClob();
      nclob2.setString(1, "aaa");
      pstmt1.setNClob(2, nclob2);                   // for setNClob(int, NClob)
      Reader reader3 = new StringReader("\'aaa\'");
      pstmt1.setNClob(3, reader3, 5);               // for setNClob(int, Reader, long)
      pstmt1.execute();
      ResultSet rs1 = this.stmt.executeQuery("SELECT c1, c2, c3 FROM testSetNClob");
      rs1.next();
      assertEquals(null, rs1.getString(1));
      assertEquals("aaa", rs1.getString(2));
      assertEquals("\'aaa\'", rs1.getString(3));
      rs1.close();
      pstmt1.close();
      conn1.close();
     
      createTable("testSetNClob", "(c1 NATIONAL CHARACTER(10), c2 NATIONAL CHARACTER(10), " +
      "c3 NATIONAL CHARACTER(10))");
      Properties props2 = new Properties();
      props2.put("useServerPrepStmts", "false"); // use client-side prepared statement
      props2.put("useUnicode", "true");
      props2.put("characterEncoding", "UTF-8"); // ensure charset is utf8 here
      Connection conn2 = getConnectionWithProps(props2);
      PreparedStatement pstmt2 =
          conn2.prepareStatement("INSERT INTO testSetNClob (c1, c2, c3) VALUES (?, ?, ?)");
      pstmt2.setNClob(1, (NClob)null);
      nclob2 = conn2.createNClob();
      nclob2.setString(1, "aaa");
      pstmt2.setNClob(2, nclob2);             // for setNClob(int, NClob)
      reader3 = new StringReader("\'aaa\'");
      pstmt2.setNClob(3, reader3, 5);         // for setNClob(int, Reader, long)
      pstmt2.execute();
      ResultSet rs2 = this.stmt.executeQuery("SELECT c1, c2, c3 FROM testSetNClob");
View Full Code Here


      props1.put("useUnicode", "true");
      props1.put("characterEncoding", "latin1"); // ensure charset isn't utf8 here
      Connection conn1 = getConnectionWithProps(props1);
      PreparedStatement pstmt1 =
          conn1.prepareStatement("INSERT INTO testSetNClobServer (c1, c2) VALUES (?, ?)");
      NClob nclob1 = conn1.createNClob();
      nclob1.setString(1, "aaa");
      Reader reader2 = new StringReader("aaa");
      try {
          pstmt1.setNClob(1, nclob1);
          fail();
      } catch (SQLException e) {
          // ok
          assertEquals("Can not call setNClob() when connection character set isn't UTF-8",
              e.getMessage())
      }
      try {
          pstmt1.setNClob(2, reader2, 3);
          fail();
      } catch (SQLException e) {
          // ok
          assertEquals("Can not call setNClob() when connection character set isn't UTF-8",
              e.getMessage())
      }
      pstmt1.close();
      conn1.close();
     
      createTable("testSetNClobServer", "(c1 NATIONAL CHARACTER(10), c2 LONGTEXT charset utf8)");
      Properties props2 = new Properties();
      props2.put("useServerPrepStmts", "true"); // use server-side prepared statement
      props2.put("useUnicode", "true");
      props2.put("characterEncoding", "UTF-8"); // ensure charset is utf8 here
      Connection conn2 = getConnectionWithProps(props2);
      PreparedStatement pstmt2 =
          conn2.prepareStatement("INSERT INTO testSetNClobServer (c1, c2) VALUES (?, ?)");
      nclob1 = conn2.createNClob();
      nclob1.setString(1, "aaa");
      pstmt2.setNClob(1, nclob1);
      pstmt2.setNClob(2, new StringReader(
              new String(new char[81921])), 81921); // 10 Full Long Data Packet's chars + 1 char
      pstmt2.execute();
      ResultSet rs2 = this.stmt.executeQuery("SELECT c1, c2 FROM testSetNClobServer");
View Full Code Here

      props1.put("characterEncoding", "UTF-8"); // ensure charset isn't utf8 here
      Connection conn1 = getConnectionWithProps(props1);
      PreparedStatement pstmt1 = conn1.prepareStatement(
              "INSERT INTO testUpdateNChlob (c1, c2) VALUES (?, ?)");
      pstmt1.setString(1, "1");
      NClob nClob1 = conn1.createNClob();
      nClob1.setString(1, "aaa");
      pstmt1.setNClob(2, nClob1);
      pstmt1.execute();
      Statement stmt1 = conn1.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
      ResultSet rs1 = stmt1.executeQuery("SELECT c1, c2 FROM testUpdateNChlob");
      rs1.next();
      NClob nClob2 = conn1.createNClob();
      nClob2.setString(1, "bbb");
      rs1.updateNClob("c2", nClob2);
      rs1.updateRow();
      rs1.moveToInsertRow();
      rs1.updateString("c1", "2");
      NClob nClob3 = conn1.createNClob();
      nClob3.setString(1, "ccc");
      rs1.updateNClob("c2", nClob3);
      rs1.insertRow();
      ResultSet rs2 = stmt1.executeQuery("SELECT c1, c2 FROM testUpdateNChlob");
      rs2.next();
      assertEquals("1", rs2.getString("c1"));
      assertEquals("bbb", rs2.getNString("c2"));
      rs2.next();
      assertEquals("2", rs2.getString("c1"));
      assertEquals("ccc", rs2.getNString("c2"));
      pstmt1.close();
      stmt1.close();
      conn1.close();
     
      createTable("testUpdateNChlob",
              "(c1 CHAR(10) PRIMARY KEY, c2 CHAR(10)) default character set sjis"); // sjis field
      Properties props2 = new Properties();
      props2.put("useServerPrepStmts", "true"); // use server-side prepared statement
      props2.put("characterEncoding", "SJIS"); // ensure charset isn't utf8 here
      Connection conn2 = getConnectionWithProps(props2);
      PreparedStatement pstmt2 = conn2.prepareStatement(
              "INSERT INTO testUpdateNChlob (c1, c2) VALUES (?, ?)");
      pstmt2.setString(1, "1");
      pstmt2.setString(2, "aaa");
      pstmt2.execute();
      Statement stmt2 = conn2.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
      ResultSet rs3 = stmt2.executeQuery("SELECT c1, c2 FROM testUpdateNChlob");
      rs3.next();
      NClob nClob4 = conn2.createNClob();
      nClob4.setString(1, "bbb");
      try {
          rs3.updateNClob("c2", nClob4); // field's charset isn't utf8
          fail();
      } catch (SQLException ex) {
          assertEquals("Can not call updateNClob() when field's character set isn't UTF-8",
View Full Code Here

   * @see java.sql.CallableStatement#getNClob(int)
   */
  public NClob getNClob(int parameterIndex) throws SQLException {
    ResultSetInternalMethods rs = getOutputParameters(parameterIndex);

    NClob retValue = ((com.mysql.jdbc.JDBC4ResultSet) rs)
        .getNClob(mapOutputParameterIndexToRsIndex(parameterIndex));

    this.outputParamWasNull = rs.wasNull();

    return retValue;
View Full Code Here

    ResultSetInternalMethods rs = getOutputParameters(0); // definitely
                                // not going to
                                // be
    // from ?=

    NClob retValue = ((com.mysql.jdbc.JDBC4ResultSet) rs)
        .getNClob(fixParameterName(parameterName));

    this.outputParamWasNull = rs.wasNull();

    return retValue;
View Full Code Here

          st.setAsciiStream(valueIndex, inputStream);
        } else if (value instanceof Reader) {
          Reader reader = (Reader) value;
          st.setCharacterStream(valueIndex, reader);
        } else if (value instanceof NClob) {
          NClob nclob = (NClob) value;
          st.setNClob(valueIndex, nclob);
        } else if (value instanceof Clob) {
          Clob clob = (Clob) value;
          st.setClob(valueIndex, clob);
        } else if (value instanceof String) {
View Full Code Here

  /**
   * {@inheritDoc}
   */
  public NClob createNClob(String string) {
    try {
      NClob nclob = createNClob();
      nclob.setString( 1, string );
      return nclob;
    }
    catch ( SQLException e ) {
      throw new JDBCException( "Unable to set NCLOB string after creation", e );
    }
View Full Code Here

  /**
   * {@inheritDoc}
   */
  public NClob createNClob(Reader reader, long length) {
    try {
      NClob nclob = createNClob();
      Writer writer = nclob.setCharacterStream( 1 );
      StreamUtils.copy( reader, writer );
      writer.flush();
      writer.close();
      return nclob;
    }
View Full Code Here

     * @tests {@link javax.sql.rowset.serial.SQLInputImpl#readNClob()}
     *
     * @since 1.6
     */
    public void testReadNClob() throws SQLException {
        NClob nclob = new MockNClob();
        Object[] attributes = new Object[] { null, nclob };
        SQLInputImpl impl = new SQLInputImpl(attributes,
                new HashMap<String, Class<?>>());
        try {
            impl.readNClob();
View Full Code Here

    public NClob connection_createNClob(ConnectionProxy connection) throws SQLException {
        if (this.pos < filterSize) {
            return nextFilter().connection_createNClob(this, connection);
        }

        NClob nclob = connection.getRawObject().createNClob();

        return wrap(connection, nclob);
    }
View Full Code Here

TOP

Related Classes of java.sql.NClob

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.