本文整理匯總了Java中java.sql.SQLWarning類的典型用法代碼示例。如果您正苦於以下問題:Java SQLWarning類的具體用法?Java SQLWarning怎麽用?Java SQLWarning使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
SQLWarning類屬於java.sql包,在下文中一共展示了SQLWarning類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getWarnings
import java.sql.SQLWarning; //導入依賴的package包/類
/**
* 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;
}
}
示例2: testBug18740
import java.sql.SQLWarning; //導入依賴的package包/類
/**
* Tests fix for BUG#18740 - Data truncation and getWarnings() only returns
* last warning in set.
*
* @throws Exception
* if the test fails.
*/
public void testBug18740() throws Exception {
if (!versionMeetsMinimum(5, 0, 2)) {
createTable("testWarnings", "(field1 smallint(6), field2 varchar(6), UNIQUE KEY field1(field1))");
try {
this.stmt.executeUpdate(
"INSERT INTO testWarnings VALUES (10001, 'data1'), (10002, 'data2 foo'), (10003, 'data3'), (10004999, 'data4'), (10005, 'data5')");
} catch (SQLException sqlEx) {
String sqlStateToCompare = "01004";
if (isJdbc4()) {
sqlStateToCompare = "22001";
}
assertEquals(sqlStateToCompare, sqlEx.getSQLState());
assertEquals(sqlStateToCompare, sqlEx.getNextException().getSQLState());
SQLWarning sqlWarn = this.stmt.getWarnings();
assertEquals("01000", sqlWarn.getSQLState());
assertEquals("01000", sqlWarn.getNextWarning().getSQLState());
}
}
}
示例3: execute
import java.sql.SQLWarning; //導入依賴的package包/類
private void execute(boolean script, boolean export, Writer fileOutput, Statement statement, final String sql)
throws IOException, SQLException {
final SqlExceptionHelper sqlExceptionHelper = new SqlExceptionHelper();
String formatted = formatter.format( sql );
if (delimiter != null) formatted += delimiter;
if (script) System.out.println(formatted);
LOG.debug(formatted);
if ( outputFile != null ) {
fileOutput.write( formatted + "\n" );
}
if ( export ) {
statement.executeUpdate( sql );
try {
SQLWarning warnings = statement.getWarnings();
if ( warnings != null) {
sqlExceptionHelper.logAndClearWarnings( connectionHelper.getConnection() );
}
}
catch( SQLException sqle ) {
LOG.unableToLogSqlWarnings(sqle);
}
}
}
示例4: test14
import java.sql.SQLWarning; //導入依賴的package包/類
/**
* Validate that the ordering of the returned SQLWarning is correct using
* traditional while loop
*/
@Test
public void test14() {
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;
SQLWarning sqe = ex;
while (sqe != null) {
assertTrue(warnings[num++].equals(sqe.getMessage()));
Throwable c = sqe.getCause();
while (c != null) {
assertTrue(msgs[num++].equals(c.getMessage()));
c = c.getCause();
}
sqe = sqe.getNextWarning();
}
}
示例5: test10
import java.sql.SQLWarning; //導入依賴的package包/類
/**
* 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);
}
示例6: test6
import java.sql.SQLWarning; //導入依賴的package包/類
/**
* Create SQLWarning with message, SQLState, and Throwable
*/
@Test
public void test6() {
SQLWarning ex = new SQLWarning(reason, state, t);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState().equals(state)
&& cause.equals(ex.getCause().toString())
&& ex.getErrorCode() == 0);
}
示例7: setWarnings
import java.sql.SQLWarning; //導入依賴的package包/類
/**
* Sets the warning chain
*/
void setWarnings(SQLWarning w) {
synchronized (rootWarning_mutex) {
rootWarning = w;
}
}
示例8: addWarning
import java.sql.SQLWarning; //導入依賴的package包/類
/**
* Adds another SQLWarning to this Connection object's warning chain.
*
* @param w the SQLWarning to add to the chain
*/
void addWarning(SQLWarning w) {
// PRE: w is never null
synchronized (rootWarning_mutex) {
if (rootWarning == null) {
rootWarning = w;
} else {
rootWarning.setNextWarning(w);
}
}
}
示例9: walkWarnings
import java.sql.SQLWarning; //導入依賴的package包/類
/**
* Generic algorithm to walk the hierarchy of SQLWarnings
*
* @param warning The warning to walk
* @param handler The handler
*/
public void walkWarnings(
SQLWarning warning,
WarningHandler handler) {
if ( warning == null || handler.doProcess() ) {
return;
}
handler.prepare( warning );
while ( warning != null ) {
handler.handleWarning( warning );
warning = warning.getNextWarning();
}
}
示例10: test5
import java.sql.SQLWarning; //導入依賴的package包/類
/**
* 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);
}
示例11: test8
import java.sql.SQLWarning; //導入依賴的package包/類
/**
* Create SQLWarning with null Throwable
*/
@Test
public void test8() {
SQLWarning ex = new SQLWarning((Throwable) null);
assertTrue(ex.getMessage() == null
&& ex.getSQLState() == null
&& ex.getCause() == null
&& ex.getErrorCode() == 0);
}
示例12: test1
import java.sql.SQLWarning; //導入依賴的package包/類
/**
* Create SQLWarning with no-arg constructor
*/
@Test
public void test1() {
SQLWarning ex = new SQLWarning();
assertTrue(ex.getMessage() == null
&& ex.getSQLState() == null
&& ex.getCause() == null
&& ex.getErrorCode() == 0);
}
示例13: test4
import java.sql.SQLWarning; //導入依賴的package包/類
/**
* 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);
}
示例14: performPostExecute
import java.sql.SQLWarning; //導入依賴的package包/類
/**
* processes chained warnings and any generated columns result set
*/
void performPostExecute() throws SQLException {
resultOut.clearLobResults();
generatedResult = null;
if (resultIn == null) {
return;
}
rootWarning = null;
Result current = resultIn;
while (current.getChainedResult() != null) {
current = current.getUnlinkChainedResult();
if (current.getType() == ResultConstants.WARNING) {
SQLWarning w = JDBCUtil.sqlWarning(current);
if (rootWarning == null) {
rootWarning = w;
} else {
rootWarning.setNextWarning(w);
}
} else if (current.getType() == ResultConstants.ERROR) {
errorResult = current;
} else if (current.getType() == ResultConstants.GENERATED) {
generatedResult = current;
} else if (current.getType() == ResultConstants.DATA) {
resultIn.addChainedResult(current);
}
}
if (rootWarning != null) {
connection.setWarnings(rootWarning);
}
}
示例15: test
import java.sql.SQLWarning; //導入依賴的package包/類
/**
* Create SQLWarning and setting all objects to null
*/
@Test
public void test() {
SQLWarning e = new SQLWarning(null, null, errorCode, null);
assertTrue(e.getMessage() == null && e.getSQLState() == null
&& e.getCause() == null && e.getErrorCode() == errorCode);
}