List of usage examples for java.sql SQLException SQLException
public SQLException(Throwable cause)
SQLException
object with a given cause
. From source file:jef.database.DefaultSqlProcessor.java
public String toCountSql(String sql) throws SQLException { // ??/*w ww . j a v a 2s . c o m*/ try { SelectBody select = DbUtils.parseNativeSelect(sql).getSelectBody(); SelectToCountWrapper sw; if (select instanceof Union) { sw = new SelectToCountWrapper((Union) select); } else { sw = new SelectToCountWrapper((PlainSelect) select, getProfile()); } return sw.toString(); } catch (ParseException e) { throw new SQLException("Parser error:" + sql); } }
From source file:gr.osmosis.rcpsamples.contact.db.derby.DerbyContactsDAO.java
public boolean updateContact(Contact contact) { if (contact == null) { throw new NullPointerException("contact parameter"); }/*w ww . j a v a 2 s. c o m*/ int rows = 0; try { StringBuffer sbUpdate = new StringBuffer(); sbUpdate.append("UPDATE "); sbUpdate.append(ContactsConstants.CONTACTS_TABLE_NAME); sbUpdate.append(" SET "); sbUpdate.append(ContactsConstants.CONTACTS_COL_FNAME + " = '" + contact.getFname() + "' , "); sbUpdate.append(ContactsConstants.CONTACTS_COL_LNAME + " = '" + contact.getLname() + "' , "); sbUpdate.append(ContactsConstants.CONTACTS_COL_PHONE + " = '" + contact.getPhone() + "' , "); sbUpdate.append(ContactsConstants.CONTACTS_COL_ADDRESS + " = '" + contact.getAddress() + "' , "); sbUpdate.append(ContactsConstants.CONTACTS_COL_CITY + " = '" + contact.getCity() + "' , "); sbUpdate.append(ContactsConstants.CONTACTS_COL_ZIP + " = '" + contact.getZip() + "' "); sbUpdate.append(" WHERE " + ContactsConstants.CONTACTS_COL_ID + " = " + contact.getId()); DataSource d = DerbyDAOFactory.getDataSource(); QueryRunner run = new QueryRunner(d); rows = run.update(sbUpdate.toString()); if (rows != 1) { throw new SQLException("executeUpdate return value: " + rows); } } catch (SQLException ex) { // throw new DAORuntimeException(ex); System.out.println(ex.getMessage()); return false; } return true; }
From source file:com.facebook.presto.jdbc.PrestoConnection.java
@Override public void rollback() throws SQLException { checkOpen();// ww w.j av a 2s. c o m if (getAutoCommit()) { throw new SQLException("Connection is in auto-commit mode"); } throw new NotImplementedException("Connection", "rollback"); }
From source file:io.cloudslang.content.database.utils.SQLUtilsTest.java
@Test public void testProcessLoadExceptionNoState() throws SQLException { expectedEx.expect(SQLException.class); expectedEx.expectMessage("test"); SQLUtils.processLoadException(new SQLException("test")); }
From source file:com.taobao.tddl.jdbc.atom.jdbc.TStatementWrapper.java
protected void increaseConcurrentRead() throws SQLException { int maxConcurrentReadRestrict = datasourceWrapper.connectionProperties.maxConcurrentReadRestrict; int concurrentReadCount = datasourceWrapper.concurrentReadCount.incrementAndGet(); if (maxConcurrentReadRestrict != 0) { if (concurrentReadCount > maxConcurrentReadRestrict) { datasourceWrapper.readTimesReject.incrementAndGet(); throw new SQLException("maxConcurrentReadRestrict reached , " + maxConcurrentReadRestrict); }// ww w . j a v a 2 s. c o m } }
From source file:es.tid.cosmos.platform.injection.server.FrontendPassword.java
/** * Connect to the platform frontend database with the configured credentials. * * @param url the frontend database host URL * @param dbName the frontend database name, if any * @param userName the username to connect to the frontend database * @param password the password to connect to the frontend database *//*from www . j a v a2 s . co m*/ private Connection connect(String url, String dbName, String userName, String password) throws SQLException { if (url == null) { throw new IllegalArgumentException("no database URL set up"); } // if try { String driver = ""; if (url.contains("sqlite")) { driver = "org.sqlite.JDBC"; } else if (url.contains("mysql")) { driver = "com.mysql.jdbc.Driver"; } // if else if if (driver.isEmpty()) { throw new SQLException("Missing driver"); } // if Class.forName(driver).newInstance(); return DriverManager.getConnection(url + dbName, userName, password); } catch (Exception e) { LOG.error(e.getMessage(), e); throw new SQLException(e); } // try catch }
From source file:com.softberries.klerk.dao.ProductDao.java
@Override public void deleteAll() throws SQLException { try {/*from w w w .ja v a2s . c o m*/ init(); st = conn.prepareStatement(SQL_DELETE_ALL_PRODUCTS); int i = st.executeUpdate(); System.out.println("i: " + i); if (i == -1) { System.out.println("db error : " + SQL_DELETE_ALL_PRODUCTS); } conn.commit(); } catch (Exception e) { //rollback the transaction but rethrow the exception to the caller conn.rollback(); e.printStackTrace(); throw new SQLException(e); } finally { close(conn, st, generatedKeys); } }
From source file:com.treasuredata.jdbc.TDDatabaseMetaData.java
public ResultSet getCatalogs() throws SQLException { DatabaseSummary ds = null;/*from www .j a v a 2 s .c om*/ try { ds = api.showDatabase(); } catch (ClientException e) { throw new SQLException(e); } ArrayList<TDDatabase> databases = new ArrayList<TDDatabase>(); if (ds != null) { TDDatabase database = new TDDatabase(ds.getName()); databases.add(database); } List<String> names = Arrays.asList("TABLE_CAT"); List<String> types = Arrays.asList("STRING"); try { ResultSet result = new TDMetaDataResultSet<TDDatabase>(names, types, databases) { private int cnt = 0; public boolean next() throws SQLException { if (cnt >= data.size()) { return false; } TDDatabase d = data.get(cnt); List<Object> a = new ArrayList<Object>(1); a.add(d.getDatabaseName()); // TABLE_CAT String => table // catalog (may be null) row = a; cnt++; return true; } }; return result; } catch (Exception e) { throw new SQLException(e); } }
From source file:org.neo4j.jdbc.http.HttpResultSet.java
@Override public String getString(int columnIndex) throws SQLException { String object = null;/*from w w w . ja v a 2s.co m*/ checkClosed(); Object value = get(columnIndex); if (value != null) { final Class<?> type = value.getClass(); if (String.class.equals(type)) { object = (String) value; } else { if (type.isPrimitive() || Number.class.isAssignableFrom(type)) { object = value.toString(); } else { try { object = OBJECT_MAPPER.writeValueAsString(value); } catch (Exception e) { throw new SQLException("Couldn't convert value " + value + " of type " + type + " to JSON " + e.getMessage()); } } } } return object; }
From source file:com.aliyun.odps.jdbc.OdpsForwardResultSet.java
@Override public boolean next() throws SQLException { checkClosed();//from ww w .jav a 2 s. c o m if (fetchedRows == totalRows) { long end = System.currentTimeMillis(); conn.log.fine("It took me " + (end - startTime) + " ms to fetch all records"); // For forward result set, we implicitly close it after fetching all records close(); return false; } // Tolerate the network problem by simply reopen the reader int retry = 0; while (true) { try { if (reader == null) { rebuildReader(); accumTime = System.currentTimeMillis(); } reuseRecord = reader.read(reuseRecord); int columns = reuseRecord.getColumnCount(); currentRow = new Object[columns]; for (int i = 0; i < columns; i++) { currentRow[i] = reuseRecord.get(i); } fetchedRows++; // Log the time consumption for fetching a bunch of rows if (fetchedRows % ACCUM_FETCHED_ROWS == 0 && fetchedRows != 0) { long delta = reader.getTotalBytes() / 1024 - accumKBytes; long duration = System.currentTimeMillis() - accumTime; conn.log.fine(String.format("fetched %d rows, %d KB, %.2f KB/s", ACCUM_FETCHED_ROWS, delta, (float) delta / duration * 1000)); accumKBytes = reader.getTotalBytes() / 1024; accumTime = System.currentTimeMillis(); } return true; } catch (IOException e) { conn.log.info("read from a bad file, retry=" + retry); if (++retry == READER_REOPEN_TIME_MAX) { throw new SQLException("to much retries because: " + e.getMessage()); } rebuildReader(); } } }