use of java.sql.SQLWarning in project dbeaver by serge-rider.
the class TableToolDialog method getScriptListener.
@Override
protected SQLScriptProgressListener<PostgreObject> getScriptListener() {
return new SQLScriptStatusDialog<PostgreObject>(getShell(), getTitle() + " progress", null) {
@Override
protected void createStatusColumns(Tree objectTree) {
TreeColumn msgColumn = new TreeColumn(objectTree, SWT.NONE);
msgColumn.setText("Message");
}
@Override
public void processObjectResults(@NotNull PostgreObject object, @Nullable DBCStatement statement, @Nullable DBCResultSet resultSet) throws DBCException {
if (statement == null) {
return;
}
TreeItem treeItem = getTreeItem(object);
if (treeItem != null) {
try {
int warnNum = 0;
SQLWarning warning = ((JDBCStatement) statement).getWarnings();
while (warning != null) {
if (warnNum == 0) {
treeItem.setText(1, warning.getMessage());
} else {
TreeItem warnItem = new TreeItem(treeItem, SWT.NONE);
warnItem.setText(0, "");
warnItem.setText(1, warning.getMessage());
}
warnNum++;
warning = warning.getNextWarning();
}
if (warnNum == 0) {
treeItem.setText(1, "Done");
}
} catch (SQLException e) {
// ignore
}
treeItem.setExpanded(true);
}
}
@Override
public void endObjectProcessing(@NotNull PostgreObject object, Exception error) {
super.endObjectProcessing(object, error);
if (error != null) {
TreeItem treeItem = getTreeItem(object);
if (treeItem != null) {
treeItem.setText(1, error.getMessage());
}
}
}
};
}
use of java.sql.SQLWarning in project robovm by robovm.
the class OldStatementTest method testGetWarnings.
public void testGetWarnings() throws SQLException {
Statement st = null;
int errorCode1 = -1;
int errorCode2 = -1;
try {
st = conn.createStatement();
st.execute("select animals from zoooo");
fail("SQLException was not thrown");
} catch (SQLException e) {
// expected
errorCode1 = e.getErrorCode();
}
SQLWarning wrs = st.getWarnings();
assertNull(wrs);
/*
Statement st = null;
int errorCode1 = -1;
int errorCode2 = -1;
try {
st = conn.createStatement();
st.execute("select animals from zoooo");
} catch (SQLException e) {
// expected
errorCode1 = e.getErrorCode();
}
try {
SQLWarning wrs = st.getWarnings();
assertNull(wrs);
} catch (Exception e) {
fail("Unexpected Exception: " + e.getMessage());
}
try {
st.execute("select horse from zoooooo");
} catch (SQLException e) {
// expected
errorCode2 = e.getErrorCode();
}
try {
SQLWarning wrs = st.getWarnings();
assertEquals(errorCode1, wrs.getErrorCode());
assertNotNull(wrs.getNextWarning());
assertEquals(errorCode2, wrs.getErrorCode());
} catch (Exception e) {
fail("Unexpected Exception: " + e.getMessage());
}
try {
st.close();
} catch (SQLException ee) {
}
*/
}
use of java.sql.SQLWarning in project adempiere by adempiere.
the class Convert method execute.
// setVerbose
/**************************************************************************
* Execute SQL Statement (stops at first error).
* If an error occurred hadError() returns true.
* You can get details via getConversionError() or getException()
* @param sqlStatements
* @param conn connection
* @return true if success
* @throws IllegalStateException if no connection
*/
public boolean execute(String sqlStatements, Connection conn) {
if (conn == null)
throw new IllegalStateException("Require connection");
//
String[] sql = convert(sqlStatements);
m_exception = null;
if (m_conversionError != null || sql == null)
return false;
boolean ok = true;
int i = 0;
String statement = null;
try {
if (m_stmt == null)
m_stmt = conn.createStatement();
//
for (i = 0; ok && i < sql.length; i++) {
statement = sql[i];
if (statement.length() == 0) {
if (m_verbose)
log.finer("Skipping empty (" + i + ")");
} else {
if (m_verbose)
log.info("Executing (" + i + ") <<" + statement + ">>");
else
log.info("Executing " + i);
try {
m_stmt.clearWarnings();
int no = m_stmt.executeUpdate(statement);
SQLWarning warn = m_stmt.getWarnings();
if (warn != null) {
if (m_verbose)
log.info("- " + warn);
else {
log.info("Executing (" + i + ") <<" + statement + ">>");
log.info("- " + warn);
}
}
if (m_verbose)
log.fine("- ok " + no);
} catch (SQLException ex) {
// Ignore Drop Errors
if (!statement.startsWith("DROP ")) {
ok = false;
m_exception = ex;
}
if (!m_verbose)
log.info("Executing (" + i + ") <<" + statement + ">>");
log.info("Error executing " + i + "/" + sql.length + " = " + ex);
}
}
}
// for all statements
} catch (SQLException e) {
m_exception = e;
if (!m_verbose)
log.info("Executing (" + i + ") <<" + statement + ">>");
log.info("Error executing " + i + "/" + sql.length + " = " + e);
return false;
}
return ok;
}
use of java.sql.SQLWarning in project voltdb by VoltDB.
the class JDBCStatementBase method performPostExecute.
/**
* processes chained warnings and any generated columns result set
*/
void performPostExecute() throws SQLException {
resultOut.clearLobResults();
generatedResult = null;
if (resultIn == null) {
return;
}
Result current = resultIn;
while (current.getChainedResult() != null) {
current = current.getUnlinkChainedResult();
if (current.getType() == ResultConstants.WARNING) {
SQLWarning w = Util.sqlWarning(current);
if (rootWarning == null) {
rootWarning = w;
} else {
rootWarning.setNextWarning(w);
}
} else if (current.getType() == ResultConstants.ERROR) {
errorResult = current;
} else if (current.getType() == ResultConstants.DATA) {
generatedResult = current;
}
}
if (resultIn.isData()) {
currentResultSet = new JDBCResultSet(connection.sessionProxy, this, resultIn, resultIn.metaData, connection.connProperties);
}
}
use of java.sql.SQLWarning in project jdk8u_jdk by JetBrains.
the class SQLWarningTests method test13.
/**
* 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()));
}
}
Aggregations