List of usage examples for java.sql SQLException SQLException
public SQLException(Throwable cause)
SQLException
object with a given cause
. From source file:com.gvmax.data.queue.JDBCBasedQueueDAO.java
@Override @Timed/*from w w w . ja va2s .c o m*/ @ExceptionMetered public List<QueueEntry<T>> getEntries(long since, int max) throws IOException { return jdbcTemplate.query("select * from " + tableName + " where id > ? limit " + max, new Object[] { since }, new RowMapper<QueueEntry<T>>() { @Override public QueueEntry<T> mapRow(ResultSet rs, int row) throws SQLException { QueueEntry<T> entry = new QueueEntry<T>(); entry.setId(rs.getLong("id")); entry.setEnqueuedDate(rs.getLong("enqueuedDate")); try { entry.setPayload(fromJson(rs.getString("payload"))); } catch (IOException e) { throw new SQLException(e); } return entry; } }); }
From source file:org.h2gis.drivers.geojson.GeoJsonWriteDriver.java
/** * Write the spatial table to GeoJSON format. * * @param progress/* ww w . j a v a 2 s. c om*/ * @throws SQLException * @throws java.io.IOException */ public void write(ProgressVisitor progress) throws SQLException, IOException { if (FileUtil.isExtensionWellFormated(fileName, "geojson")) { writeGeoJson(progress); } else { throw new SQLException("Only .geojson extension is supported"); } }
From source file:FacultyAdvisement.StudentRepository.java
public static void adminUpdate(DataSource ds, Student student, String oldUsername) throws SQLException { Connection conn = ds.getConnection(); if (conn == null) { throw new SQLException("conn is null; Can't get db connection"); }/*from ww w . j a v a 2s . c o m*/ try { PreparedStatement ps; ps = conn.prepareStatement( "Update STUDENT set EMAIL=?, FIRSTNAME=?, LASTNAME=?, MAJORCODE=?, PHONE=?, ADVISED=? where STUID=?"); ps.setString(1, student.getUsername()); ps.setString(2, student.getFirstName()); ps.setString(3, student.getLastName()); ps.setString(4, student.getMajorCode()); ps.setString(5, student.getPhoneNumber()); if (student.isAdvised()) { ps.setString(6, "true"); } else { ps.setString(6, "false"); } ps.setString(7, student.getId()); ps.executeUpdate(); ps = conn.prepareStatement("Update USERTABLE set USERNAME=? where USERNAME=?"); ps.setString(1, student.getUsername()); ps.setString(2, oldUsername); ps.executeUpdate(); ps = conn.prepareStatement("Update GROUPTABLE set USERNAME=? where USERNAME=?"); ps.setString(1, student.getUsername()); ps.setString(2, oldUsername); ps.executeUpdate(); if (student.isResetPassword()) { String newPassword = UUID.randomUUID().toString(); String encryptedPassword = SHA256Encrypt.encrypt(newPassword); ps = conn.prepareStatement("Update USERTABLE set PASSWORD=? where USERNAME=?"); ps.setString(1, encryptedPassword); ps.setString(2, student.getUsername()); ps.executeUpdate(); Email email = new HtmlEmail(); email.setHostName("smtp.googlemail.com"); email.setSmtpPort(465); email.setAuthenticator(new DefaultAuthenticator("uco.faculty.advisement", "!@#$1234")); email.setSSLOnConnect(true); email.setFrom("uco.faculty.advisement@gmail.com"); email.setSubject("UCO Faculty Advisement Password Change"); email.setMsg("<font size=\"3\">An admin has resetted your password, your new password is \"" + newPassword + "\"." + "\n<p align=\"center\">UCO Faculty Advisement</p></font>"); email.addTo(student.getUsername()); email.send(); } } catch (EmailException ex) { Logger.getLogger(StudentRepository.class.getName()).log(Level.SEVERE, null, ex); } finally { conn.close(); } //students = (HashMap<String, StudentPOJO>) readAll(); // reload the updated info }
From source file:io.lavagna.common.ConstructorAnnotationRowMapper.java
@Override public T mapRow(ResultSet rs, int rowNum) throws SQLException { List<Object> vals = new ArrayList<>(mappedColumn.size()); for (ColumnMapper colMapper : mappedColumn) { vals.add(colMapper.getObject(rs)); }//from w w w .j av a 2s . c om try { return con.newInstance(vals.toArray(new Object[vals.size()])); } catch (ReflectiveOperationException e) { throw new SQLException(e); } catch (IllegalArgumentException e) { throw new SQLException("type mismatch between the expected one from the construct and the one passed," + " check 1: some values are null and passed to primitive types 2: incompatible numeric types", e); } }
From source file:biz.wolschon.finance.jgnucash.mysql.impl.TransactionRowMapper.java
/** * @param aResultSet the result-set whos current result to map * @param aRowNumber the current row-number in the result-set * @return the result mapped to a bean// w w w . j av a 2s.c o m * @throws SQLException on problems with the database * @see org.springframework.jdbc.core.simple.ParameterizedRowMapper#mapRow(java.sql.ResultSet, int) */ @Override public GnucashDBTransaction mapRow(final ResultSet aResultSet, final int aRowNumber) throws SQLException { GnucashDBTransaction retval; try { retval = new GnucashDBTransaction(myGnucashFile, aResultSet.getString("guid"), aResultSet.getString("currency_guid"), aResultSet.getString("num"), aResultSet.getString("description"), MYDATEFORMAT.parse(aResultSet.getString("post_date")), MYDATEFORMAT.parse(aResultSet.getString("enter_date"))); } catch (ParseException e) { SQLException ex = new SQLException("invalid date"); ex.initCause(e); throw ex; } return retval; }
From source file:com.taobao.adfs.database.tdhsocket.client.response.TDHSResutSet.java
private void checkRow(int columnIndex) throws SQLException { if (currentRow == null) { throw new SQLException("can't find current row"); }//w w w.j a v a 2 s . c om if (columnIndex <= 0 || columnIndex > currentRow.size()) { throw new SQLException("Invaild column:" + columnIndex); } }
From source file:org.jtalks.poulpe.util.databasebackup.persistence.DbTableData.java
/** * The method prepares table's data in the shape and passes every {@link Row} into given RowProcessor. * /* w ww.j av a 2 s. co m*/ * @param processor * injected logic to perform some actions under passing rows. see details for {@link RowProcessor}. * @throws SQLException * if any errors during work with database occur. */ public void getData(final RowProcessor processor) throws SQLException { try { jdbcTemplate.query(SELECT_FROM + tableName, new RowCallbackHandler() { @Override public void processRow(ResultSet rs) throws SQLException { ResultSetMetaData metaData = rs.getMetaData(); int columnCount = metaData.getColumnCount(); Row row = new Row(); for (int i = 1; i <= columnCount; i++) { ColumnMetaData columnMetaData = ColumnMetaData.getInstance(metaData.getColumnName(i), SqlTypes.getSqlTypeByJdbcSqlType(metaData.getColumnType(i))); row.addCell(columnMetaData, rs.getObject(i)); } try { processor.process(row); } catch (RowProcessingException e) { throw new SQLException(e); } } }); } catch (DataAccessException e) { throw new SQLException(e); } }
From source file:com.tacitknowledge.util.migration.jdbc.util.SqlUtil.java
/** * Established and returns a connection based on the specified parameters. * * @param driver the JDBC driver to use//from w w w.jav a2 s .com * @param url the database URL * @param user the username * @param pass the password * @return a JDBC connection * @throws ClassNotFoundException if the driver could not be loaded * @throws SQLException if a connnection could not be made to the database */ public static Connection getConnection(String driver, String url, String user, String pass) throws ClassNotFoundException, SQLException { Connection conn = null; try { Class.forName(driver); log.debug("Getting Connection to " + url); conn = DriverManager.getConnection(url, user, pass); } catch (Exception e) { /* work around for DriverManager 'feature'. * In some cases, the jdbc driver jar is injected into a new * child classloader (for example, maven provides different * class loaders for different build lifecycle phases). * * Since DriverManager uses the calling class' loader instead * of the current context's loader, it fails to find the driver. * * Our work around is to give the current context's class loader * a shot at finding the driver in cases where DriverManager fails. * This 'may be' a security hole which is why DriverManager implements * things in such a way that it doesn't use the current thread context class loader. */ try { Class driverClass = Class.forName(driver, true, Thread.currentThread().getContextClassLoader()); Driver driverImpl = (Driver) driverClass.newInstance(); Properties props = new Properties(); props.put("user", user); props.put("password", pass); conn = driverImpl.connect(url, props); } catch (InstantiationException ie) { log.debug(ie); throw new SQLException(ie.getMessage()); } catch (IllegalAccessException iae) { log.debug(iae); throw new SQLException(iae.getMessage()); } } return conn; }
From source file:com.tesora.dve.dbc.ServerDBConnection.java
public boolean execute(String sql) throws SQLException { boolean rv = false; initialize();/*www . ja v a2 s.co m*/ final MysqlTextResultCollector resultConsumer = new MysqlTextResultCollector(); try { executeInContext(resultConsumer, sql.getBytes()); rv = resultConsumer.hasResults(); } catch (PEMysqlErrorException e) { throw new SQLException(e); } catch (PEException e) { throw new SQLException(e); } catch (Throwable t) { throw new SQLException(t); } finally { ssCon.releaseNonTxnLocks(); } return rv; }
From source file:jp.primecloud.auto.tool.management.db.SQLExecuter.java
public void execute(String sql) throws SQLException, Exception { Connection con = null;//from w w w. j a v a 2s . c o m Statement stmt = null; ResultSet rs = null; String logSQL = ""; // ?? logSQL = passwordMask(sql); log.info("[" + logSQL + "] ???"); try { con = dbConnector.getConnection(); stmt = con.createStatement(); stmt.execute(sql); log.info("[" + logSQL + "] ????"); } catch (SQLException e) { log.error(passwordMask(e.getMessage()), e); throw new SQLException(e); } catch (Exception e) { log.error(passwordMask(e.getMessage()), e); throw new Exception(e); } finally { try { dbConnector.closeConnection(con, stmt, rs); } catch (Exception e) { e.printStackTrace(); } } }