Package java.sql

Examples of java.sql.SQLWarning


    else if (stmt.getResultSetConcurrency() == JDBC20Translation.CONCUR_READ_ONLY)
      concurrencyOfThisResultSet = JDBC20Translation.CONCUR_READ_ONLY;
    else {
      if (!isForUpdate()) { //language resultset not updatable
        concurrencyOfThisResultSet = JDBC20Translation.CONCUR_READ_ONLY;
        SQLWarning w = StandardException.newWarning(SQLState.QUERY_NOT_QUALIFIED_FOR_UPDATABLE_RESULTSET);
        addWarning(w);
      } else
          concurrencyOfThisResultSet = JDBC20Translation.CONCUR_UPDATABLE;
    }
View Full Code Here


         * connection and we won't be able to do the close later
         */
        throw closeOnTransactionError(t);
      }
        
      SQLWarning w = theResults.getWarnings();
      if (w != null) {
        if (topWarning == null)
          topWarning = w;
        else
          topWarning.setNextWarning(w);
View Full Code Here

                    act.getParameterValueSet().getParameterForSet(paramPosition++).setValue(updateRow.getColumn(i));
            }
            // Don't set any timeout when updating rows (use 0)
            // Execute the update where current of sql.
            org.apache.derby.iapi.sql.ResultSet rs = ps.execute(act, true, 0L);
            SQLWarning w = act.getWarnings();
            if (w != null) {
                addWarning(w);
            }
            rs.close();
            rs.finish();
View Full Code Here

                Activation act = ps.getActivation(lcc, false);
                // Don't set any timeout when deleting rows (use 0)
                //execute delete where current of sql
                org.apache.derby.iapi.sql.ResultSet rs =
                        ps.execute(act, true, 0L);
                SQLWarning w = act.getWarnings();
                if (w != null) {
                    addWarning(w);
                }
                rs.close();
                rs.finish();
View Full Code Here

    throws SQLException
  {
    boolean    passed = true;
    PreparedStatement  ps_f_r = null;
    ResultSet  rs;
    SQLWarning  warning;
    Statement  s_f_r = null;

    s_f_r = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY,
                   ResultSet.CONCUR_READ_ONLY);
    // We should have gotten no warnings and a read only forward only cursor
    warning = conn.getWarnings();
    while (warning != null)
    {
      System.out.println("warning = " + warning);
      warning = warning.getNextWarning();
    }
    conn.clearWarnings();

    // Verify that setMaxRows(-1) fails
    try
    {
      s_f_r.setMaxRows(-1);
      // Should never get here
      System.out.println("setMaxRows(-1) expected to fail");
      passed = false;
    }
    catch (SQLException sqle)
    {
      /* Check to be sure the exception is the one we expect */
                        if (!isDerbyNetClient) {
                            passed = passed && checkException(sqle, "XJ063");
                        } else {
                            System.out.println(sqle.getMessage());
                        }
    }
    // Verify maxRows still 0
    if (s_f_r.getMaxRows() != 0)
    {
      System.out.println("getMaxRows() expected to return 0");
      passed = false;
    }

    // Verify that result set from statement is
    // scroll insensitive and read only
    rs = s_f_r.executeQuery("select * from t");
    if (rs.getType() != ResultSet.TYPE_FORWARD_ONLY)
    {
      System.out.println("cursor type = " + rs.getType() +
                 ", not " + ResultSet.TYPE_FORWARD_ONLY);
    }
    if (rs.getConcurrency() != ResultSet.CONCUR_READ_ONLY)
    {
      System.out.println("concurrency = " + rs.getConcurrency() +
                 ", not " + ResultSet.CONCUR_READ_ONLY);
    }

    // Verify that first(), etc. don't work
    try
    {
      rs.first();
      // Should never get here
      System.out.println("first() expected to fail");
      passed = false;
    }
    catch (SQLException sqle)
    {
      /* Check to be sure the exception is the one we expect */
                        if (!isDerbyNetClient) {
                            passed = passed && checkException(sqle, "XJ061");
                        } else {
                            System.out.println(sqle.getMessage());
                        }

    }
    try
    {
      rs.beforeFirst();
      // Should never get here
      System.out.println("beforeFirst() expected to fail");
      passed = false;
    }
    catch (SQLException sqle)
    {
      /* Check to be sure the exception is the one we expect */
                        if (!isDerbyNetClient) {
                            passed = passed && checkException(sqle, "XJ061");
                        } else {
                            System.out.println(sqle.getMessage());
                        }

    }
    try
    {
      rs.isBeforeFirst();
      // Should never get here
      System.out.println("isBeforeFirst() expected to fail");
      passed = false;
    }
    catch (SQLException sqle)
    {
      /* Check to be sure the exception is the one we expect */
                        if (!isDerbyNetClient) {
                            passed = passed && checkException(sqle, "XJ061");
                        } else {
                            System.out.println(sqle.getMessage());
                        }

    }
    try
    {
      rs.isAfterLast();
      // Should never get here
      System.out.println("isAfterLast() expected to fail");
      passed = false;
    }
    catch (SQLException sqle)
    {
      /* Check to be sure the exception is the one we expect */
                        if (!isDerbyNetClient) {
                            passed = passed && checkException(sqle, "XJ061");
                        } else {
                            System.out.println(sqle.getMessage());
                        }

    }
    try
    {
      rs.isFirst();
      // Should never get here
      System.out.println("isFirst() expected to fail");
      passed = false;
    }
    catch (SQLException sqle)
    {
      /* Check to be sure the exception is the one we expect */
                        if (!isDerbyNetClient) {
                            passed = passed && checkException(sqle, "XJ061");
                        } else {
                            System.out.println(sqle.getMessage());
                        }
    }
    try
    {
      rs.isLast();
      // Should never get here
      System.out.println("isLast() expected to fail");
      passed = false;
    }
    catch (SQLException sqle)
    {
      /* Check to be sure the exception is the one we expect */
                        if (!isDerbyNetClient) {
                            passed = passed && checkException(sqle, "XJ061");
                        } else {
                            System.out.println(sqle.getMessage());
                        }
    }
    try
    {
      rs.absolute(1);
      // Should never get here
      System.out.println("absolute() expected to fail");
      passed = false;
    }
    catch (SQLException sqle)
    {
      /* Check to be sure the exception is the one we expect */
                        if (!isDerbyNetClient) {
                            passed = passed && checkException(sqle, "XJ061");
                        } else {
                            System.out.println(sqle.getMessage());
                        }
    }
    try
    {
      rs.relative(1);
      // Should never get here
      System.out.println("relative() expected to fail");
      passed = false;
    }
    catch (SQLException sqle)
    {
      /* Check to be sure the exception is the one we expect */
                        if (!isDerbyNetClient) {
                            passed = passed && checkException(sqle, "XJ061");
                        } else {
                            System.out.println(sqle.getMessage());
                        }
    }

    // setFetchDirection should fail
    try
    {
      rs.setFetchDirection(ResultSet.FETCH_FORWARD);
      // Should never get here
      System.out.println("setFetchDirection() expected to fail");
      passed = false;
    }
    catch (SQLException sqle)
    {
      /* Check to be sure the exception is the one we expect */
                        if (!isDerbyNetClient) {
                            passed = passed && checkException(sqle, "XJ061");
                        } else {
                            System.out.println(sqle.getMessage());
                        }
    }

    /* Book says that getFetchDirection(), getFetchSize() and
     * setFetchSize() are all okay.
     */
    if ((rs.getFetchSize() != 1 && !isDerbyNetClient) || (rs.getFetchSize() != 0 && isDerbyNetClient))
     {
                        if (!isDerbyNetClient) {
                            System.out.println("getFetchSize() expected to return 1");
                        } else {
                            System.out.println("getFetchSize() expected to return 0");
                        }
                        passed = false;
    }
    rs.setFetchSize(5);
    if (rs.getFetchSize() != 5)
     {
      System.out.println("getFetchSize() expected to return 5");
      passed = false;
    }

    if (rs.getFetchDirection() != ResultSet.FETCH_FORWARD)
    {
      System.out.println(
        "getFetchDirection() expected to return FETCH_FORWARD, not " +
        rs.getFetchDirection());
      passed = false;
    }

    rs.close();
    s_f_r.close();

    ps_f_r = conn.prepareStatement(
                   "select * from t",
                   ResultSet.TYPE_FORWARD_ONLY,
                   ResultSet.CONCUR_READ_ONLY);
    // We should have gotten no warnings and a read only forward only cursor
    warning = conn.getWarnings();
    while (warning != null)
    {
      System.out.println("warning = " + warning);
      warning = warning.getNextWarning();
    }
    conn.clearWarnings();

    // Verify that result set from statement is
    // scroll insensitive and read only
View Full Code Here

  static boolean forwardOnlyPositive( Connection conn)
    throws SQLException
  {
    boolean    passed = true;
    ResultSet  rs;
    SQLWarning  warning;
    Statement  s_f_r = null;

    s_f_r = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY,
                   ResultSet.CONCUR_READ_ONLY);
    // We should have gotten no warnings and a read only forward only cursor
    warning = conn.getWarnings();
    while (warning != null)
    {
      System.out.println("warning = " + warning);
      warning = warning.getNextWarning();
    }
    conn.clearWarnings();

    // Verify that setMaxRows(4) succeeds
    s_f_r.setMaxRows(5);
View Full Code Here

  static boolean scrollSensitiveTest( Connection conn)
    throws SQLException
  {
    ResultSet  rs;
    SQLWarning  warning;
    Statement  s_s_r = null; // sensitive, read only
    Statement  s_s_u = null; // sensitive, updatable


    s_s_r = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
                   ResultSet.CONCUR_READ_ONLY);

    // We should have gotten a warning and a scroll insensitive cursor
    warning = conn.getWarnings();
    while (warning != null)
    {
      System.out.println("warning = " + warning);
      warning = warning.getNextWarning();
    }
    conn.clearWarnings();

    // Verify that result set from statement is
    // scroll insensitive and read only
    rs = s_s_r.executeQuery("select * from t");
    if (rs.getType() != ResultSet.TYPE_SCROLL_INSENSITIVE)
    {
      System.out.println("cursor type = " + rs.getType() +
                 ", not " + ResultSet.TYPE_SCROLL_INSENSITIVE);
    }
    if (rs.getConcurrency() != ResultSet.CONCUR_READ_ONLY)
    {
      System.out.println("concurrency = " + rs.getConcurrency() +
                 ", not " + ResultSet.CONCUR_READ_ONLY);
    }
    rs.close();

    // Close the statement
    s_s_r.close();

    s_s_u = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
                   ResultSet.CONCUR_UPDATABLE);
    // We should have gotten 1 warning and a updatable scroll
    // insensitive cursor.
    warning = conn.getWarnings();
    while (warning != null)
    {
      System.out.println("warning = " + warning);
      warning = warning.getNextWarning();
    }
    conn.clearWarnings();

    // Verify that result set from statement is
    // scroll insensitive and read only
View Full Code Here

    throws SQLException
  {
    boolean   passed = true;
    PreparedStatement ps_i_r = null;
    ResultSet  rs;
    SQLWarning  warning;
    Statement  s_i_r = null; // insensitive, read only


    s_i_r = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
                   ResultSet.CONCUR_READ_ONLY);

    // We should not have gotten any warnings
    // and should have gotten a scroll insensitive cursor
    warning = conn.getWarnings();
    while (warning != null)
    {
      System.out.println("unexpected warning = " + warning);
      warning = warning.getNextWarning();
      passed = false;
    }
    conn.clearWarnings();

    // run a query
    rs = s_i_r.executeQuery("select * from t");
    // verify scroll insensitive and read only
    if (rs.getType() != ResultSet.TYPE_SCROLL_INSENSITIVE)
    {
      System.out.println(
        "rs.getType() expected to return TYPE_SCROLL_INSENSITIVE, not " +
        rs.getType());
      passed = false;
    }
    if (rs.getConcurrency() != ResultSet.CONCUR_READ_ONLY)
    {
      System.out.println(
        "rs.getConcurrency() expected to return CONCUR_READ_ONLY, not " +
        rs.getConcurrency());
      passed = false;
    }
   
    // We should be positioned before the 1st row
    if (! rs.isBeforeFirst())
    {
      System.out.println("expected to be before the 1st row");
      passed = false;
    }
                if (rs.absolute(0))
                {
      System.out.println("absolute(0) expected to return false");
      passed = false;
                }
    if (! rs.isBeforeFirst())
    {
      System.out.println("still expected to be before the 1st row");
      passed = false;
    }
    // go to first row
    if (! rs.first())
    {
      System.out.println("expected first() to succeed");
      passed = false;
    }
    if (rs.getInt(1) != 2)
    {
      System.out.println(
        "rs.getInt(1) expected to return 2, not " + rs.getInt(1));
      passed = false;
    }
    if (! rs.isFirst())
    {
      System.out.println("expected to be on the 1st row");
      passed = false;
    }
    // move to before first
    rs.beforeFirst();
    if (! rs.isBeforeFirst())
    {
      System.out.println("expected to be before the 1st row");
      passed = false;
    }
    // move to last row
    if (! rs.last())
    {
      System.out.println("expected last() to succeed");
      passed = false;
    }
    if (! rs.isLast())
    {
      System.out.println("expected to be on the last row");
      passed = false;
    }
    if (rs.isAfterLast())
    {
      System.out.println("not expected to be after the last row");
      passed = false;
    }
    if (rs.getInt(1) != 6)
    {
      System.out.println(
        "rs.getInt(1) expected to return 6, not " + rs.getInt(1));
      passed = false;
    }
    if (rs.next())
    {
      System.out.println("not expected to find another row");
      passed = false;
    }
    if (! rs.isAfterLast())
    {
      System.out.println("expected to be after the last row");
      passed = false;
    }

    // We're after the last row, verify that only isAfterLast()
    // returns true
    if (rs.isLast())
    {
      System.out.println("not expected to be on the last row");
      passed = false;
    }
    if (rs.isFirst())
    {
      System.out.println("not expected to be on the first row");
      passed = false;
    }
    if (rs.isBeforeFirst())
    {
      System.out.println("not expected to be before the first row");
      passed = false;
    }

    // get/setFetchDirection()
    if (rs.getFetchDirection() != ResultSet.FETCH_FORWARD)
    {
      System.out.println(
        "getFetchDirection() expected to return FETCH_FORWARD, not " +
        rs.getFetchDirection());
      passed = false;
    }
    rs.setFetchDirection(ResultSet.FETCH_UNKNOWN);
    if (rs.getFetchDirection() != ResultSet.FETCH_UNKNOWN)
    {
      System.out.println(
        "getFetchDirection() expected to return FETCH_UNKNOWN, not " +
        rs.getFetchDirection());
      passed = false;
    }

    // get/setFetchSize()
    if (
                        (rs.getFetchSize() != 1 && !isDerbyNetClient) ||
                        (rs.getFetchSize() != 64 && isDerbyNetClient))
    {
                        if (!isDerbyNetClient) {
                            System.out.println(
                                    "getFetchSize() expected to return 1, not " + rs.getFetchSize());
                        } else {
                            System.out.println(
                                    "getFetchSize() expected to return 64, not " + rs.getFetchSize());
                        }
      passed = false;
    }
    rs.setFetchSize(5);
    if (rs.getFetchSize() != 5)
    {
      System.out.println(
        "getFetchSize() expected to return 5, not " + rs.getFetchSize());
      passed = false;
    }
    // setFetchSize() to 0 should have no effect.
                // for client server, fetchSize should have to 64
    rs.setFetchSize(0);
    if (
                        (rs.getFetchSize() != 5 && !isDerbyNetClient) ||
                        (rs.getFetchSize() != 64 && isDerbyNetClient))
    {
                        if (!isDerbyNetClient) {
                            System.out.println(
        "getFetchSize() expected to return 5, not " + rs.getFetchSize());
                        } else {
                            System.out.println(
        "getFetchSize() expected to return 64, not " + rs.getFetchSize());
                        }

      passed = false;
    }
    // done
    rs.close();


    // Empty result set tests (DERBY-992)
    rs = s_i_r.executeQuery("select * from t where 1=0");
    rs.afterLast();
    if (rs.isAfterLast()) {
      System.out.println("afterLast() on empty RS should be no-op");
    }
   
    rs.beforeFirst();
    if (rs.isBeforeFirst()) {
      System.out.println("beforeFirst() on empty RS should be no-op");
    }

    rs.close();

    ps_i_r = conn.prepareStatement(
                   "select * from t",
                   ResultSet.TYPE_SCROLL_INSENSITIVE,
                   ResultSet.CONCUR_READ_ONLY);

    // We should not have gotten any warnings
    // and should have gotten a prepared scroll insensitive cursor
    warning = conn.getWarnings();
    while (warning != null)
    {
      System.out.println("unexpected warning = " + warning);
      warning = warning.getNextWarning();
      passed = false;
    }
    conn.clearWarnings();

    rs = ps_i_r.executeQuery();
View Full Code Here

  static boolean scrollInsensitiveNegative( Connection conn)
    throws SQLException
  {
    boolean   passed = true;
    ResultSet  rs;
    SQLWarning  warning;
    Statement  s_i_r = null; // insensitive, read only

    s_i_r = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
                   ResultSet.CONCUR_READ_ONLY);

    // We should not have gotten any warnings
    // and should have gotten a scroll insensitive cursor
    warning = conn.getWarnings();
    while (warning != null)
    {
      System.out.println("unexpected warning = " + warning);
      warning = warning.getNextWarning();
      passed = false;
    }
    conn.clearWarnings();

    // Verify that setMaxRows(-1) fails
View Full Code Here

  public static boolean testCallableStatements( Connection conn)
    throws SQLException
  {
    boolean    passed = true;
    int      warningCount = 0;
    SQLWarning  warning;
    CallableStatement  cs_s_r = null; // sensitive, read only
    CallableStatement  cs_s_u = null; // sensitive, updatable
    CallableStatement  cs_i_r = null; // insensitive, read only
    CallableStatement  cs_f_r = null; // forward only, read only

    cs_s_r = conn.prepareCall(
                "values cast (? as Integer)",
                ResultSet.TYPE_SCROLL_SENSITIVE,
                ResultSet.CONCUR_READ_ONLY);

    // We should have gotten 1 warnings
    warning = conn.getWarnings();
    while (warning != null)
    {
      System.out.println("warning = " + warning);
      warning = warning.getNextWarning();
      warningCount++;
    }
    if (warningCount != 1)
    {
      System.out.println("warningCount expected to be 1, not " +
          warningCount);
      passed = false;
    }
    conn.clearWarnings();
    cs_s_r.close()

    cs_s_u = conn.prepareCall(
                "values cast (? as Integer)",
                ResultSet.TYPE_SCROLL_SENSITIVE,
                ResultSet.CONCUR_UPDATABLE);

    // We should have gotten 2 warnings
    warningCount = 0;
    warning = conn.getWarnings();
    while (warning != null)
    {
      System.out.println("warning = " + warning);
      warning = warning.getNextWarning();
      warningCount++;
    }
    // SCROLL_INSENSITIVE and UPDATABLE implemented
    if (warningCount != 1)
    {
      System.out.println("warningCount expected to be 1, not " + warningCount);
      passed = false;
    }
    conn.clearWarnings();
    cs_s_u.close()

    cs_i_r = conn.prepareCall(
                "values cast (? as Integer)",
                ResultSet.TYPE_SCROLL_INSENSITIVE,
                ResultSet.CONCUR_READ_ONLY);

    // We should have gotten 0 warnings
    warningCount = 0;
    warning = conn.getWarnings();
    while (warning != null)
    {
      System.out.println("warning = " + warning);
      warning = warning.getNextWarning();
      warningCount++;
    }
    if (warningCount != 0)
    {
      System.out.println("warningCount expected to be 0, not " +
          warningCount);
      passed = false;
    }
    conn.clearWarnings();
    cs_i_r.close()

    cs_f_r = conn.prepareCall(
                "values cast (? as Integer)",
                ResultSet.TYPE_FORWARD_ONLY,
                ResultSet.CONCUR_READ_ONLY);

    // We should have gotten 0 warnings
    warningCount = 0;
    warning = conn.getWarnings();
    while (warning != null)
    {
      System.out.println("warning = " + warning);
      warning = warning.getNextWarning();
      warningCount++;
    }
    if (warningCount != 0)
    {
      System.out.println("warningCount expected to be 0, not " + warningCount);
View Full Code Here

TOP

Related Classes of java.sql.SQLWarning

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.