java.sql.SQLWarning Java Examples

The following examples show how to use java.sql.SQLWarning. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StatementImpl.java    From Komondor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * The first warning reported by calls on this Statement is returned. A
 * Statement's execute methods clear its java.sql.SQLWarning chain.
 * Subsequent Statement warnings will be chained to this
 * java.sql.SQLWarning.
 * 
 * <p>
 * The Warning chain is automatically cleared each time a statement is (re)executed.
 * </p>
 * 
 * <p>
 * <B>Note:</B> If you are processing a ResultSet then any warnings associated with ResultSet reads will be chained on the ResultSet object.
 * </p>
 * 
 * @return the first java.sql.SQLWarning or null
 * 
 * @exception SQLException
 *                if a database access error occurs
 */
public java.sql.SQLWarning getWarnings() throws SQLException {
    synchronized (checkClosed().getConnectionMutex()) {

        if (this.clearWarningsCalled) {
            return null;
        }

        if (this.connection.versionMeetsMinimum(4, 1, 0)) {
            SQLWarning pendingWarningsFromServer = SQLError.convertShowWarningsToSQLWarnings(this.connection);

            if (this.warningChain != null) {
                this.warningChain.setNextWarning(pendingWarningsFromServer);
            } else {
                this.warningChain = pendingWarningsFromServer;
            }

            return this.warningChain;
        }

        return this.warningChain;
    }
}
 
Example #2
Source File: SURTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Test that you get a warning when specifying a query which is not
 * updatable and concurrency mode CONCUR_UPDATABLE.
 * In this case, the query contains an "order by"
 */
public void testConcurrencyModeWarning1()
    throws SQLException 
{
    Statement s = createStatement(ResultSet.TYPE_FORWARD_ONLY,
                                      ResultSet.CONCUR_UPDATABLE);
    s.setCursorName(getNextCursorName());
    ResultSet rs = s.executeQuery("select * from t1 order by a");
    
    SQLWarning warn = rs.getWarnings();
    assertEquals("Expected resultset to be read only",
                 ResultSet.CONCUR_READ_ONLY,
                 rs.getConcurrency());
    assertWarning(warn, QUERY_NOT_QUALIFIED_FOR_UPDATABLE_RESULTSET);
    scrollForward(rs);
    rs.close();
    s.close();
}
 
Example #3
Source File: Subquery.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
private int updateFromTable(PreparedStatement stmt,  int whichUpdate, int qty,
    int tid, int sid, int sid2) throws SQLException {
  Log.getLogWriter().info("update statement is " + uniqUpdate[whichUpdate]);
  int rowCount = 0;
  switch (whichUpdate) {
  case 0:  
    Log.getLogWriter().info("updating record where sid between " + sid + 
        " and " + sid2 + " and tid is " +tid);
    stmt.setInt(1, qty);
    stmt.setInt(2,tid);
    stmt.setInt(3, sid);
    stmt.setInt(4, sid2);
    rowCount = stmt.executeUpdate();
    break;
  default:
    throw new TestException("incorrect update statement, should not happen");
  }  
  SQLWarning warning = stmt.getWarnings(); //test to see there is a warning
  if (warning != null) {
    SQLHelper.printSQLWarning(warning);
  } 
  return rowCount;
}
 
Example #4
Source File: TradeCustomersDMLTxStmt.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
protected int deleteToTableTidListTx(PreparedStatement stmt, int cid, String cust_name,
		int whichDelete, int tid) throws SQLException {
   int rowCount = 0;
   switch (whichDelete) {
   case 0: 
		//"delete from trade.customers where cid=? and tid=? ", 
     Log.getLogWriter().info("delete from customers for cid: " + cid + " and tid: " + tid);
     stmt.setInt(1, cid);
     stmt.setInt(2, tid);
     rowCount = stmt.executeUpdate();    
     break;
   case 1: 
		//"delete from trade.customers where (cust_name > ? or cid < ? ) and tid = ?",
     Log.getLogWriter().info("delete from customers for cust_name>'" + cust_name  + "'and " +
     		"cid< " + cid + " and tid: " + tid);
     stmt.setString(1, cust_name);
     stmt.setInt(2, cid);
     stmt.setInt(3, tid);
     rowCount = stmt.executeUpdate();       
     break;
   default:
    throw new TestException ("Wrong delete sql string here");
   }
   SQLWarning warning = stmt.getWarnings(); //test to see there is a warning
   if (warning != null) {
     SQLHelper.printSQLWarning(warning);
   } 
   return rowCount;		
}
 
Example #5
Source File: SQLWarningTests.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create SQLWarning with Throwable
 */
@Test
public void test9() {
    SQLWarning ex = new SQLWarning(t);
    assertTrue(ex.getMessage().equals(cause)
            && ex.getSQLState() == null
            && cause.equals(ex.getCause().toString())
            && ex.getErrorCode() == 0);
}
 
Example #6
Source File: TradeBuyOrdersDMLTxStmt.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
protected int deleteToTableCidRangeTx(PreparedStatement stmt, int cid, int cid2, 
		int oid, BigDecimal bid, int whichDelete) throws SQLException { 
   int rowCount = 0;
   switch (whichDelete) {
   case 0: 
 		//"delete from trade.buyorders where cid=? and oid=? and bid <?",
     Log.getLogWriter().info("deleting from buyorders table for cid: " + cid 
     		+ " and oid: " + oid + " and bid<" + bid);
     stmt.setInt(1, cid);
     stmt.setInt(2, oid);
     stmt.setBigDecimal(3, bid);
     rowCount = stmt.executeUpdate();
     break;
   case 1: 
     // "delete from trade.buyorders where cid>? and cid<? and status IN ('cancelled', 'filled')",  
     Log.getLogWriter().info("deleting from buyorders table for cid> "+ cid + " to cid< " + cid2 + 
     		" and status IN ('cancelled', 'filled')");
     stmt.setInt(1, cid);
     stmt.setInt(2, cid2);
     rowCount =  stmt.executeUpdate();
    break;
   default:
    throw new TestException ("Wrong update sql string here");
   }
   SQLWarning warning = stmt.getWarnings(); //test to see there is a warning
   if (warning != null) {
     SQLHelper.printSQLWarning(warning);
   } 
   return rowCount;		
}
 
Example #7
Source File: SQLWarningTests.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create SQLWarning with message
 */
@Test
public void test2() {
    SQLWarning ex = new SQLWarning(reason);
    assertTrue(ex.getMessage().equals(reason)
            && ex.getSQLState() == null
            && ex.getCause() == null
            && ex.getErrorCode() == 0);
}
 
Example #8
Source File: PrestoResultSet.java    From presto with Apache License 2.0 5 votes vote down vote up
@Override
public SQLWarning getWarnings()
        throws SQLException
{
    checkOpen();
    return null;
}
 
Example #9
Source File: ProcedureDDLStmt.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
protected void exeProcedure(Connection conn, String procedure) throws SQLException {
  Statement stmt = conn.createStatement();
  stmt.executeUpdate(procedure);    
  SQLWarning warning = stmt.getWarnings(); //test to see there is a warning
  if (warning != null) {
    SQLHelper.printSQLWarning(warning);
  } 
}
 
Example #10
Source File: SQLWarningTests.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create SQLWarning with message, SQLState, and error code
 */
@Test
public void test4() {
    SQLWarning ex = new SQLWarning(reason, state, errorCode);
    assertTrue(ex.getMessage().equals(reason)
            && ex.getSQLState().equals(state)
            && ex.getCause() == null
            && ex.getErrorCode() == errorCode);
}
 
Example #11
Source File: PrestoConnection.java    From presto with Apache License 2.0 5 votes vote down vote up
@Override
public SQLWarning getWarnings()
        throws SQLException
{
    checkOpen();
    return null;
}
 
Example #12
Source File: GfxdMessage.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/** log the warnings, if any, in execution of an SQL statement */
public static void logWarnings(Statement stmt, String sqlText, String prefix,
    LogWriter logger) throws SQLException {
  SQLWarning warning = stmt.getWarnings();
  if (warning != null) {
    if (logger.warningEnabled()) {
      logger.warning(prefix + sqlText + " "+ warning.getMessage(), null);
    }
    while ((warning = warning.getNextWarning()) != null) {
      if (logger.warningEnabled()) {
        logger.warning(prefix + sqlText + " " + warning.getMessage(), null);
      }
    }
  }
}
 
Example #13
Source File: SQLWarningTests.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Validate that the ordering of the returned SQLWarning is correct using
 * for-each loop
 */
@Test
public void test13() {
    SQLWarning ex = new SQLWarning("Warning 1", t1);
    SQLWarning ex1 = new SQLWarning("Warning 2");
    SQLWarning ex2 = new SQLWarning("Warning 3", t2);
    ex.setNextWarning(ex1);
    ex.setNextWarning(ex2);
    int num = 0;
    for (Throwable e : ex) {
        assertTrue(warnings[num++].equals(e.getMessage()));
    }
}
 
Example #14
Source File: SnowflakeConnectionV1.java    From snowflake-jdbc with Apache License 2.0 5 votes vote down vote up
@Override
public SQLWarning getWarnings() throws SQLException
{
  logger.debug("SQLWarning getWarnings()");
  raiseSQLExceptionIfConnectionIsClosed();
  return sqlWarnings;
}
 
Example #15
Source File: TradeCustomersV1DMLDistTxStmt.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
protected int deleteFromTable(PreparedStatement stmt, long cid, int tid, 
    int whichDelete) throws SQLException {
  
  int txId = (Integer) SQLDistTxTest.curTxId.get();
  String database =  SQLHelper.isDerbyConn(stmt.getConnection()) ? "Derby - " : "gemfirexd - TXID:" + txId + " " ;
  String query = " QUERY: " + delete[whichDelete];
  
  int rowCount=0;
  switch (whichDelete) {
  case 0:   
    //"delete from trade.customersv1 where cid=?",
    Log.getLogWriter().info(database + "deleting from trade.customersv1 " +
    		"with CID:" +cid + query);
    stmt.setLong(1, cid);
    rowCount = stmt.executeUpdate();
    Log.getLogWriter().info(database + "deleted " + rowCount + " rows from " +
    		"trade.customersv1 with CID:" +cid + query);
    break;
  case 1:
    //"delete from trade.customersv1 where cid in (? , ?) ", 
    Log.getLogWriter().info(database + "deleting from trade.customersv1 with" +
    		" CID:" + cid +",CID:" + (cid-tid) + query);
    stmt.setLong(1, cid);
    stmt.setLong(2, cid-tid);
    rowCount = stmt.executeUpdate();
    Log.getLogWriter().info(database + "deleted " + rowCount + " rows from " +
    		"trade.customersv1 with CID:" + cid +",CID:" + (cid-tid) + query);
    break;
  default:
    throw new TestException("incorrect delete statement, should not happen");
  }  
  SQLWarning warning = stmt.getWarnings(); //test to see there is a warning
  if (warning != null) {
    SQLHelper.printSQLWarning(warning);
  } 
  return rowCount;
}
 
Example #16
Source File: NetworkServerControlImpl.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
	 * Connect to a database to test whether a connection can be made
	 *
	 * @param writer	connection to send message to
	 * @param database 	database directory to connect to
	 * @param user		user to use
	 * @param password	password to use
	 */
	private void connectToDatabase(DDMWriter writer, String database, String user, 
		String password) throws Exception
	{
		Properties p = new Properties();
		if (user != null)
			p.put("user", user);
		if (password != null)
			p.put("password", password);
	 	try {
     		Class.forName(CLOUDSCAPE_DRIVER);
		}
		catch (Exception e) {
			sendMessage(writer, ERROR, e.getMessage());
			return;
	  	}
	 	try {
			//Note, we add database to the url so that we can allow additional
			//url attributes
// GemStone changes BEGIN
	 	  Connection conn = DriverManager.getConnection(com.pivotal.gemfirexd.Attribute.PROTOCOL, p);
			/* Connection conn = DriverManager.getConnection(Attribute.PROTOCOL+database, p); */
// GemStone changes END
			// send warnings
			SQLWarning warn = conn.getWarnings();
			if (warn != null)
				sendSQLMessage(writer, warn, SQLWARNING);
			else
				sendOK(writer);
			conn.close();
			return;
	  	} catch (SQLException se) {
			sendSQLMessage(writer, se, SQLERROR);
	  	}
	}
 
Example #17
Source File: TradeSecuritiesDMLDistTxStmtJson.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
protected int deleteFromTable(PreparedStatement stmt, int sec_id, String symbol, 
    String exchange, int tid, int whichDelete) throws SQLException {
  
  int txId = (Integer) SQLDistTxTest.curTxId.get();
  String database =  SQLHelper.isDerbyConn(stmt.getConnection()) ? "Derby - " : "gemfirexd - TXID:" + txId + " " ;
  String query = " QUERY: " + delete[whichDelete];
  
  if (!SQLHelper.isDerbyConn(stmt.getConnection()))
    query = " QUERY: " + deleteJSON[whichDelete];
  
  int rowCount=0;
  switch (whichDelete) {
  case 0:   
    //delete from trade.securities where sec_id=?",
    Log.getLogWriter().info(database + "deleteing from trade.securities with SECID:" +sec_id + query);
    stmt.setInt(1, sec_id);
    rowCount = stmt.executeUpdate();
    Log.getLogWriter().info(database + "deleted " + rowCount + " rows from trade.securities with SECID:" +sec_id + query);
    break;
  case 1:
    //"delete from trade.securities where (symbol like ? and exchange = ? ) and tid=?"
    Log.getLogWriter().info(database + "deleteing from trade.securities with  SYMBOL:" + symbol +",EXCHANGE:" + exchange + ",TID:" + tid + query);
    stmt.setString(1, symbol);
    stmt.setString(2, exchange);
    stmt.setInt(3, tid);
    rowCount = stmt.executeUpdate();
    Log.getLogWriter().info(database + "deleted " + rowCount + " rows from trade.securities with  SYMBOL:" + symbol +",EXCHANGE:" + exchange + ",TID:" + tid + query);
    break;
  default:
    throw new TestException("incorrect delete statement, should not happen");
  }  
  SQLWarning warning = stmt.getWarnings(); //test to see there is a warning
  if (warning != null) {
    SQLHelper.printSQLWarning(warning);
  } 
  return rowCount;
}
 
Example #18
Source File: TestStatementListenerDispatcher.java    From jaybird with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Test if call to {@link org.firebirdsql.gds.ng.listeners.StatementListenerDispatcher#warningReceived(org.firebirdsql.gds.ng.FbStatement, java.sql.SQLWarning)}
 * is forwarded correctly.
 */
@Test
public void testWarningReceived() {
    final Expectations expectations = new Expectations();
    final SQLWarning warning = new SQLWarning();
    expectations.exactly(1).of(listener).warningReceived(statement, warning);
    context.checking(expectations);

    dispatcher.warningReceived(statement, warning);
}
 
Example #19
Source File: SQLWarningTests.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create SQLWarning with message, SQLState, and error code
 */
@Test
public void test4() {
    SQLWarning ex = new SQLWarning(reason, state, errorCode);
    assertTrue(ex.getMessage().equals(reason)
            && ex.getSQLState().equals(state)
            && ex.getCause() == null
            && ex.getErrorCode() == errorCode);
}
 
Example #20
Source File: StatementWrapper.java    From Komondor with GNU General Public License v3.0 5 votes vote down vote up
public SQLWarning getWarnings() throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            return this.wrappedStmt.getWarnings();
        }

        throw SQLError.createSQLException("Statement already closed", SQLError.SQL_STATE_ILLEGAL_ARGUMENT, this.exceptionInterceptor);
    } catch (SQLException sqlEx) {
        checkAndFireConnectionError(sqlEx);
    }

    return null;
}
 
Example #21
Source File: StatementWrapper.java    From Oceanus with Apache License 2.0 5 votes vote down vote up
@Override
public SQLWarning getWarnings() throws SQLException {
	if (statements.size() > 0) {
		return statements.iterator().next().getWarnings();
	}
	throw new UnsupportedOperationException();
}
 
Example #22
Source File: TradeSellOrdersDMLTxStmt.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
protected int deleteToTableTidListTx(PreparedStatement stmt, int oid1, int oid2,
		int oid, int whichDelete, int tid) throws SQLException {
   int rowCount = 0;
   switch (whichDelete) {
   case 0: 
		//"delete from trade.sellorders where oid=? and tid=? ",
     Log.getLogWriter().info("deleting from sellorders for oid: " + oid 
     		+ " and tid: " + tid);
     stmt.setInt(1, oid);
     stmt.setInt(2, tid);
     rowCount = stmt.executeUpdate();    
     break;
   case 1: 
		//"delete from trade.sellorders where oid>? and oid<? and status IN ('cancelled', 'filled') and tid=? ",  
     Log.getLogWriter().info("deleting from sellorders for oid > " + oid1 
     		+ " oid < " + oid2 + " and status IN ('cancelled', 'filled') and tid: " + tid);
     stmt.setInt(1, oid1);
     stmt.setInt(2, oid2);
     stmt.setInt(3, tid);
     rowCount = stmt.executeUpdate();       
     break;
   default:
    throw new TestException ("Wrong delete sql string here");
   }
   SQLWarning warning = stmt.getWarnings(); //test to see there is a warning
   if (warning != null) {
     SQLHelper.printSQLWarning(warning);
   } 
   return rowCount;		
}
 
Example #23
Source File: SQLWarningTests.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Serialize a SQLWarning and make sure you can read it back properly
 */
@Test
public void test10() throws Exception {
    SQLWarning e = new SQLWarning(reason, state, errorCode, t);
    SQLWarning ex1 = createSerializedException(e);
    assertTrue(reason.equals(ex1.getMessage())
            && ex1.getSQLState().equals(state)
            && cause.equals(ex1.getCause().toString())
            && ex1.getErrorCode() == errorCode);
}
 
Example #24
Source File: SnowflakeBaseResultSet.java    From snowflake-jdbc with Apache License 2.0 5 votes vote down vote up
@Override
public SQLWarning getWarnings() throws SQLException
{
  logger.debug("public SQLWarning getWarnings()");
  raiseSQLExceptionIfResultSetIsClosed();
  return null;
}
 
Example #25
Source File: SQLWarningTests.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create SQLWarning with message, and SQLState
 */
@Test
public void test3() {

    SQLWarning ex = new SQLWarning(reason, state);
    assertTrue(ex.getMessage().equals(reason)
            && ex.getSQLState().equals(state)
            && ex.getCause() == null
            && ex.getErrorCode() == 0);
}
 
Example #26
Source File: SQLWarningTests.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create SQLWarning with message, SQLState, errorCode, and Throwable
 */
@Test
public void test5() {
    SQLWarning ex = new SQLWarning(reason, state, errorCode, t);
    assertTrue(ex.getMessage().equals(reason)
            && ex.getSQLState().equals(state)
            && cause.equals(ex.getCause().toString())
            && ex.getErrorCode() == errorCode);
}
 
Example #27
Source File: JdbcPoolConnection.java    From XPagesExtensionLibrary with Apache License 2.0 5 votes vote down vote up
public SQLWarning getWarnings() throws SQLException {
    //try {
        return connection.getWarnings();
    //} catch( SQLException e ) {
    //    throw sqlExceptionThrown(e);
    //}
}
 
Example #28
Source File: AvaticaResultSet.java    From calcite-avatica with Apache License 2.0 4 votes vote down vote up
public SQLWarning getWarnings() throws SQLException {
  checkOpen();
  return null; // no warnings, since warnings are not supported
}
 
Example #29
Source File: GenericActivationHolder.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public SQLWarning getResultsetWarnings()
{
        return ac.getResultsetWarnings();
}
 
Example #30
Source File: NativeProtocol.java    From FoxTelem with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Turns output of 'SHOW WARNINGS' into JDBC SQLWarning instances.
 * 
 * If 'forTruncationOnly' is true, only looks for truncation warnings, and
 * actually throws DataTruncation as an exception.
 * 
 * @param warningCountIfKnown
 *            the warning count (if known), otherwise set it to 0.
 * @param forTruncationOnly
 *            if this method should only scan for data truncation warnings
 * 
 * @return the SQLWarning chain (or null if no warnings)
 */
public SQLWarning convertShowWarningsToSQLWarnings(int warningCountIfKnown, boolean forTruncationOnly) {
    SQLWarning currentWarning = null;
    ResultsetRows rows = null;

    try {
        /*
         * +---------+------+---------------------------------------------+
         * | Level ..| Code | Message ....................................|
         * +---------+------+---------------------------------------------+
         * | Warning | 1265 | Data truncated for column 'field1' at row 1 |
         * +---------+------+---------------------------------------------+
         */
        NativePacketPayload resultPacket = sendCommand(this.commandBuilder.buildComQuery(getSharedSendPacket(), "SHOW WARNINGS"), false, 0);

        Resultset warnRs = readAllResults(-1, warningCountIfKnown > 99 /* stream large warning counts */, resultPacket, false, null,
                new ResultsetFactory(Type.FORWARD_ONLY, Concurrency.READ_ONLY));

        int codeFieldIndex = warnRs.getColumnDefinition().findColumn("Code", false, 1) - 1;
        int messageFieldIndex = warnRs.getColumnDefinition().findColumn("Message", false, 1) - 1;
        String enc = warnRs.getColumnDefinition().getFields()[messageFieldIndex].getEncoding();

        ValueFactory<String> svf = new StringValueFactory(enc);
        ValueFactory<Integer> ivf = new IntegerValueFactory();

        rows = warnRs.getRows();
        Row r;
        while ((r = rows.next()) != null) {

            int code = r.getValue(codeFieldIndex, ivf);

            if (forTruncationOnly) {
                if (code == MysqlErrorNumbers.ER_WARN_DATA_TRUNCATED || code == MysqlErrorNumbers.ER_WARN_DATA_OUT_OF_RANGE) {
                    DataTruncation newTruncation = new MysqlDataTruncation(r.getValue(messageFieldIndex, svf), 0, false, false, 0, 0, code);

                    if (currentWarning == null) {
                        currentWarning = newTruncation;
                    } else {
                        currentWarning.setNextWarning(newTruncation);
                    }
                }
            } else {
                //String level = warnRs.getString("Level"); 
                String message = r.getValue(messageFieldIndex, svf);

                SQLWarning newWarning = new SQLWarning(message, MysqlErrorNumbers.mysqlToSqlState(code), code);
                if (currentWarning == null) {
                    currentWarning = newWarning;
                } else {
                    currentWarning.setNextWarning(newWarning);
                }
            }
        }

        if (forTruncationOnly && (currentWarning != null)) {
            throw ExceptionFactory.createException(currentWarning.getMessage(), currentWarning);
        }

        return currentWarning;
    } catch (IOException ex) {
        throw ExceptionFactory.createException(ex.getMessage(), ex);
    } finally {
        if (rows != null) {
            rows.close();
        }
    }
}