本文整理匯總了Java中java.sql.SQLException.toString方法的典型用法代碼示例。如果您正苦於以下問題:Java SQLException.toString方法的具體用法?Java SQLException.toString怎麽用?Java SQLException.toString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.sql.SQLException
的用法示例。
在下文中一共展示了SQLException.toString方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: sqlResultSetParse
import java.sql.SQLException; //導入方法依賴的package包/類
/**
* 解析resultset中的條數
*
* @param resultSet
* @return
*/
private String sqlResultSetParse(ResultSet rset) {
try {
// 隻能向前遍曆的遊標,隻能用next()來遍曆
if (rset.getType() == ResultSet.TYPE_FORWARD_ONLY) {
return "FORWARD_ONLY";
}
else {
// 可以滾動的遊標,在用戶使用遊標之前,直接獲取結果集大小,然後遊標回到開始的地方(假裝遊標沒有移動過)
rset.last();
int row = rset.getRow();
rset.beforeFirst();
return row + "";
}
}
catch (SQLException e) {
return e.toString();
}
}
示例2: rollbackThis
import java.sql.SQLException; //導入方法依賴的package包/類
/**
* This rolls back the connection associated with <i>this</i> XAResource.
*
* @throws javax.transaction.xa.XAException generically, since the more
* specific exceptions require a JTA API to compile.
*/
/* @throws javax.transaction.HeuristicCommitException
* if work was committed.
* @throws javax.transaction.HeuristicMixedException
* if some work was committed and some work was rolled back
*/
public void rollbackThis() throws XAException {
if (state != XA_STATE_PREPARED && state != XA_STATE_ENDED) {
throw new XAException("Invalid XAResource state");
}
try {
/**
* @todo: Determine if work was committed, rolled back, or both,
* and return appropriate Heuristic Exception.
*/
connection.rollback(); // real/phys.
} catch (SQLException se) {
throw new XAException(se.toString());
}
dispose();
}
示例3: read
import java.sql.SQLException; //導入方法依賴的package包/類
@Override
public int read(byte[] b) throws IOException {
if (this.currentPositionInBlob + 1 > this.length) {
return -1;
}
try {
byte[] asBytes = getBytesInternal(this.pStmt, (this.currentPositionInBlob) + 1, b.length);
if (asBytes == null) {
return -1;
}
System.arraycopy(asBytes, 0, b, 0, asBytes.length);
this.currentPositionInBlob += asBytes.length;
return asBytes.length;
} catch (SQLException sqlEx) {
throw new IOException(sqlEx.toString());
}
}
示例4: getData
import java.sql.SQLException; //導入方法依賴的package包/類
TransferResultSet getData(String statement)
throws DataAccessPointException {
ResultSet rsData = null;
try {
if (srcStatement != null) {
srcStatement.close();
}
srcStatement = conn.createStatement();
rsData = srcStatement.executeQuery(statement);
} catch (SQLException e) {
try {
srcStatement.close();
} catch (Exception e1) {}
srcStatement = null;
rsData = null;
throw new DataAccessPointException(e.toString());
}
return new TransferResultSet(rsData);
}
示例5: insert
import java.sql.SQLException; //導入方法依賴的package包/類
public final void insert(T t, List<V> values) {
if (!Db.isInTransaction()) {
throw new IllegalStateException("Not in transaction");
}
DbKey dbKey = dbKeyFactory.newKey(t);
Db.getCache(table).put(dbKey, values);
try (Connection con = Db.getConnection()) {
if (multiversion) {
try (PreparedStatement pstmt = con.prepareStatement("UPDATE " + table
+ " SET latest = FALSE " + dbKeyFactory.getPKClause() + " AND latest = TRUE")) {
dbKey.setPK(pstmt);
pstmt.executeUpdate();
}
}
for (V v : values) {
save(con, t, v);
}
} catch (SQLException e) {
throw new RuntimeException(e.toString(), e);
}
}
示例6: test
import java.sql.SQLException; //導入方法依賴的package包/類
protected boolean test(Statement aStatement) {
try {
aStatement.execute(getSql());
} catch (SQLException sqlX) {
caught = sqlX;
if (expectedState == null
|| expectedState.equalsIgnoreCase(sqlX.getSQLState())) {
return true;
}
message = "SQLState '" + sqlX.getSQLState() + "' : "
+ sqlX.toString() + " instead of '" + expectedState
+ "'";
} catch (Exception x) {
caught = x;
message = x.toString();
}
return false;
}
示例7: getBlockIdsAfter
import java.sql.SQLException; //導入方法依賴的package包/類
@Override
public List<Long> getBlockIdsAfter(long blockId, int limit) {
if (limit > 1440) {
throw new IllegalArgumentException("Can't get more than 1440 blocks at a time");
}
try (Connection con = Db.getConnection();
PreparedStatement pstmt = con.prepareStatement("SELECT id FROM block WHERE db_id > (SELECT db_id FROM block WHERE id = ?) ORDER BY db_id ASC LIMIT ?")) {
List<Long> result = new ArrayList<>();
pstmt.setLong(1, blockId);
pstmt.setInt(2, limit);
try (ResultSet rs = pstmt.executeQuery()) {
while (rs.next()) {
result.add(rs.getLong("id"));
}
}
return result;
} catch (SQLException e) {
throw new RuntimeException(e.toString(), e);
}
}
示例8: read
import java.sql.SQLException; //導入方法依賴的package包/類
@Override
public int read(byte[] b, int off, int len) throws IOException {
if (this.currentPositionInBlob + 1 > this.length) {
return -1;
}
try {
byte[] asBytes = getBytesInternal(this.pStmt, (this.currentPositionInBlob) + 1, len);
if (asBytes == null) {
return -1;
}
System.arraycopy(asBytes, 0, b, off, asBytes.length);
this.currentPositionInBlob += asBytes.length;
return asBytes.length;
} catch (SQLException sqlEx) {
throw new IOException(sqlEx.toString());
}
}
示例9: findTransaction
import java.sql.SQLException; //導入方法依賴的package包/類
protected static Long findTransaction(int startHeight , int endHeight , Long atID, int numOfTx, long minAmount){
try (Connection con = Db.getConnection();
PreparedStatement pstmt = con.prepareStatement("SELECT id FROM transaction "
+ "WHERE height>= ? AND height < ? and recipient_id = ? AND amount >= ? "
+ "ORDER BY height, id "
+ "LIMIT 1 OFFSET ?")){
pstmt.setInt(1, startHeight);
pstmt.setInt(2, endHeight);
pstmt.setLong(3, atID);
pstmt.setLong(4, minAmount);
pstmt.setInt(5, numOfTx);
ResultSet rs = pstmt.executeQuery();
Long transactionId = 0L;
if(rs.next()) {
transactionId = rs.getLong("id");
}
rs.close();
return transactionId;
} catch (SQLException e) {
throw new RuntimeException(e.toString(), e);
}
}
示例10: get
import java.sql.SQLException; //導入方法依賴的package包/類
public final List<V> get(DbKey dbKey) {
List<V> values;
if (Db.isInTransaction()) {
values = (List<V>)Db.getCache(table).get(dbKey);
if (values != null) {
return values;
}
}
try (Connection con = Db.getConnection();
PreparedStatement pstmt = con.prepareStatement("SELECT * FROM " + table + dbKeyFactory.getPKClause()
+ (multiversion ? " AND latest = TRUE" : "") + " ORDER BY db_id DESC")) {
dbKey.setPK(pstmt);
values = get(con, pstmt);
if (Db.isInTransaction()) {
Db.getCache(table).put(dbKey, values);
}
return values;
} catch (SQLException e) {
throw new RuntimeException(e.toString(), e);
}
}
示例11: TransferDb
import java.sql.SQLException; //導入方法依賴的package包/類
TransferDb(Connection c, Traceable t) throws DataAccessPointException {
super(t);
conn = c;
if (c != null) {
String productLowerName;
try {
meta = c.getMetaData();
databaseToConvert = c.getCatalog();
productLowerName = meta.getDatabaseProductName();
if (productLowerName == null) {
productLowerName = "";
} else {
productLowerName = productLowerName.toLowerCase();
}
helper = HelperFactory.getHelper(productLowerName);
helper.set(this, t, meta.getIdentifierQuoteString());
} catch (SQLException e) {
throw new DataAccessPointException(e.toString());
}
}
}
示例12: DbIterator
import java.sql.SQLException; //導入方法依賴的package包/類
public DbIterator(Connection con, PreparedStatement pstmt, ResultSetReader<T> rsReader) {
this.con = con;
this.pstmt = pstmt;
this.rsReader = rsReader;
try {
this.rs = pstmt.executeQuery();
this.hasNext = rs.next();
} catch (SQLException e) {
DbUtils.close(pstmt, con);
throw new RuntimeException(e.toString(), e);
}
}
示例13: getTransactionCount
import java.sql.SQLException; //導入方法依賴的package包/類
@Override
public int getTransactionCount() {
try (Connection con = Db.getConnection(); PreparedStatement pstmt = con.prepareStatement("SELECT COUNT(*) FROM transaction");
ResultSet rs = pstmt.executeQuery()) {
rs.next();
return rs.getInt(1);
} catch (SQLException e) {
throw new RuntimeException(e.toString(), e);
}
}
示例14: rollbackTransaction
import java.sql.SQLException; //導入方法依賴的package包/類
public static void rollbackTransaction() {
DbConnection con = localConnection.get();
if (con == null) {
throw new IllegalStateException("Not in transaction");
}
try {
con.doRollback();
} catch (SQLException e) {
throw new RuntimeException(e.toString(), e);
}
transactionCaches.get().clear();
transactionBatches.get().clear();
}
示例15: setAutoCommit
import java.sql.SQLException; //導入方法依賴的package包/類
void setAutoCommit(boolean flag) throws DataAccessPointException {
try {
conn.setAutoCommit(flag);
} catch (SQLException e) {
throw new DataAccessPointException(e.toString());
}
}