Java Code Examples for java.sql.SQLWarning

The following examples show how to use java.sql.SQLWarning. These examples are extracted from open source projects. 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 Project: Komondor   Source File: StatementImpl.java    License: 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 Project: gemfirexd-oss   Source File: Subquery.java    License: 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 3
Source Project: gemfirexd-oss   Source File: SURTest.java    License: 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 4
Source Project: XPagesExtensionLibrary   Source File: JdbcPoolConnection.java    License: 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 5
Source Project: gemfirexd-oss   Source File: ProcedureDDLStmt.java    License: 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 6
Source Project: hottub   Source File: SQLWarningTests.java    License: 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 7
Source Project: gemfirexd-oss   Source File: TradeBuyOrdersDMLTxStmt.java    License: 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 8
/**
 * 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 9
Source Project: presto   Source File: PrestoConnection.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public SQLWarning getWarnings()
        throws SQLException
{
    checkOpen();
    return null;
}
 
Example 10
Source Project: presto   Source File: PrestoResultSet.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public SQLWarning getWarnings()
        throws SQLException
{
    checkOpen();
    return null;
}
 
Example 11
Source Project: jdk8u_jdk   Source File: SQLWarningTests.java    License: 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 12
Source Project: gemfirexd-oss   Source File: GfxdMessage.java    License: 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 Project: jdk8u_jdk   Source File: SQLWarningTests.java    License: 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 Project: snowflake-jdbc   Source File: SnowflakeConnectionV1.java    License: 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
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 Project: gemfirexd-oss   Source File: NetworkServerControlImpl.java    License: 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
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
/**
 * 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
/**
 * 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 Project: Komondor   Source File: StatementWrapper.java    License: 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 Project: Oceanus   Source File: StatementWrapper.java    License: 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 Project: gemfirexd-oss   Source File: TradeSellOrdersDMLTxStmt.java    License: 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 Project: jdk8u_jdk   Source File: SQLWarningTests.java    License: 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 Project: snowflake-jdbc   Source File: SnowflakeBaseResultSet.java    License: 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
/**
 * 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 Project: jdk8u_jdk   Source File: SQLWarningTests.java    License: 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 Project: gemfirexd-oss   Source File: TradeCustomersDMLTxStmt.java    License: 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 28
Source Project: jdk8u60   Source File: StubJoinRowSetImpl.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public SQLWarning getWarnings() throws SQLException {
    throw new UnsupportedOperationException("Not supported yet.");
}
 
Example 29
@Override
public void warningReceived(FbStatement sender, SQLWarning warning) {
    warnings.add(warning);
}
 
Example 30
Source Project: tomcatsrc   Source File: ResultSet.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public SQLWarning getWarnings() throws SQLException {
    // TODO Auto-generated method stub
    return null;
}