List of usage examples for java.sql SQLException getLocalizedMessage
public String getLocalizedMessage()
From source file:swp.bibjsf.persistence.Data.java
@Override public int updateBook(int ID, Book newValue) throws DataSourceException { logger.error("updating book " + ID + " by " + newValue); try {//from ww w . j a va 2s . c om return update(bookTableName, newValue, "id", ID, null, null); } catch (SQLException e) { logger.error("failure in updating book " + e.getErrorCode()); throw new DataSourceException(e.getLocalizedMessage()); } }
From source file:swp.bibjsf.persistence.Data.java
@Override public void deleteBook(Book book) throws DataSourceException { logger.info("deleting book " + book); try {// w w w .j a v a 2 s . c o m run.update("DELETE FROM " + bookTableName + " WHERE ID = ?", book.getId()); } catch (SQLException e) { logger.error("failure in deleting book " + e.getErrorCode()); throw new DataSourceException(e.getLocalizedMessage()); } }
From source file:swp.bibjsf.persistence.Data.java
@Override public int updateReader(int ID, Reader newValue) throws DataSourceException { logger.debug("update reader " + ID); if (ID == AdminID) { logger.error("attempt to update admin"); throw new DataSourceException(Messages.get("adminmustnotbechanged")); }/*from w w w .j av a2 s.com*/ logger.error("updating reader " + ID + " by " + newValue); try { return update(readerTableName, newValue, "id", ID, null, null); } catch (SQLException e) { logger.error("failure in updating reader " + e.getErrorCode()); throw new DataSourceException(e.getLocalizedMessage()); } }
From source file:swp.bibjsf.persistence.Data.java
/** * * Creates a new instance of this class. It is checked, whether the * datasource can be provided by the application container and whether the * database has the right structure./*from w w w. j a v a 2 s. c o m*/ * * @throws DataSourceException * is thrown if there is no datasource found with this name. * * * @throws NamingException is thrown if there are problems * during the JNDI-name look-up. */ public Data() throws DataSourceException, NamingException { logger.debug("create new Data object"); Context envCtx; Context initCtx = new InitialContext(); logger.debug("lookup database: " + databaselookup + ", " + databasename); envCtx = (Context) initCtx.lookup(databaselookup); dataSource = (DataSource) envCtx.lookup(databasename); run = new QueryRunner(dataSource); try { checkDatabaseStructure(true); } catch (SQLException e) { logger.error("check database structure failure: " + e.getMessage()); throw new DataSourceException(e.getLocalizedMessage()); } }
From source file:swp.bibjsf.persistence.Data.java
@Override public void deleteReader(Reader reader) throws DataSourceException { logger.debug("delete reader " + reader); if (reader.getId() == AdminID) { logger.info("attempt to delete admin " + reader + ": ignored"); throw new DataSourceException(Messages.get("adminmustnotbechanged")); } else {// w w w . j ava2 s.co m logger.info("deleting reader " + reader); try { run.update("DELETE FROM " + readerTableName + " WHERE ID = ?", reader.getId()); } catch (SQLException e) { logger.error("failure in deleting reader " + e.getErrorCode()); throw new DataSourceException(e.getLocalizedMessage()); } } }
From source file:de.dmarcini.submatix.pclogger.gui.MainCommGUI.java
/** * Datenbankfr das Programm vorbereiten oder erzeugen Project: SubmatixBTForPC Package: de.dmarcini.submatix.pclogger.gui * //from w ww . j a v a 2s . c om * @author Dirk Marciniak (dirk_marciniak@arcor.de) Stand: 24.04.2012 */ private void prepareDatabase() { // Verbindung zum Datenbanktreiber databaseUtil = new LogDerbyDatabaseUtil(this); if (databaseUtil == null) { showErrorDialog(String.format(LangStrings.getString("MainCommGUI.databaseError.text"), "?")); lg.error("can connect to database drivers!"); System.exit(-1); } // ffne die Datenbank // ging das? try { if (databaseUtil.createConnection() == null) { System.exit(-1); } } catch (SQLException ex) { showErrorDialog(String.format(LangStrings.getString("MainCommGUI.databaseError.text"), ex.getLocalizedMessage())); ex.printStackTrace(); System.exit(-1); } catch (ClassNotFoundException ex) { showErrorDialog(String.format(LangStrings.getString("MainCommGUI.databaseError.text"), ex.getLocalizedMessage())); ex.printStackTrace(); System.exit(-1); } // hier ist alles gut... }
From source file:com.egt.core.db.xdp.RecursoCachedRowSet.java
/** * {@inheritDoc}/* w w w . ja v a2s .c o m*/ */ @Override public void acceptChanges() throws SyncProviderException { try { this.getFilasConflictivas().clear(); super.acceptChanges(); } catch (SyncProviderException spe) { SyncResolver resolver = spe.getSyncResolver(); if (resolver != null && resolver instanceof SyncResolverX) { boolean showDeleted = this.tryToGetShowDeleted(); boolean sinDuplicados = TLC.getBitacora().isSinDuplicados(); int conflictos = 0; int row; int status = SyncResolver.NO_ROW_CONFLICT; String transaction = DBUtils.getTransactionLabel(status); SQLException sqlException; int errorCode; String message; String localizedMessage; String sqlState; String heading; String clave = CBM2.COMMIT_CHANGES_UNKNOWN_EXCEPTION; int tipoError; /* OJO con la constante, 1 -> fila con un error desconocido */ String mensaje; String prefijo = Global.PREFIJO_ETIQUETA_ID_RECURSO; try { this.tryToSetShowDeleted(true); TLC.getBitacora().setSinDuplicados(true); while (resolver.nextConflict()) { conflictos++; row = resolver.getRow(); status = resolver.getStatus(); transaction = DBUtils.getTransactionLabel(status); sqlException = ((SyncResolverX) resolver).getSQLException(); errorCode = sqlException.getErrorCode(); message = sqlException.getMessage(); localizedMessage = StringUtils.substringBefore(sqlException.getLocalizedMessage(), " Where: "); sqlState = sqlException.getSQLState(); heading = "Row:" + row + ", Status:" + status + ", Code:" + errorCode + ", State:" + sqlState; Bitacora.trace(heading + message); if (TLC.getInterpreteSql().isCommandIgnoredException(sqlException)) { clave = CBM2.COMMIT_CHANGES_COMMAND_IGNORED_EXCEPTION; tipoError = 0; /* OJO con la constante, 0 -> fila "ignorada" (no se sabe si tiene o no errores) */ mensaje = tipoError + Bitacora.getTextoMensaje(clave, transaction, prefijo + row); TLC.getBitacora().error(CBM2.COMMIT_CHANGES_COMMAND_IGNORED); if (status == SyncResolver.DELETE_ROW_CONFLICT) { this.tryToSetShowDeleted(false); } } else { String columna = TLC.getInterpreteSql() .getNotNullConstraintViolationColumn(sqlException); if (StringUtils.isNotBlank(columna)) { clave = CBM2.DATABASE_NOT_NULL_CONSTRAINT_VIOLATION; tipoError = 2; /* OJO con la constante, 2 -> fila con un error conocido */ mensaje = tipoError + TLC.getBitacora().error(clave, transaction, prefijo + row, columna); } else { clave = DBUtils.getConstraintMessageKey(message, status); if (clave == null) { clave = CBM2.COMMIT_CHANGES_UNKNOWN_EXCEPTION; tipoError = 1; /* OJO con la constante, 1 -> fila con un error desconocido */ mensaje = tipoError + TLC.getBitacora().error(clave, transaction, prefijo + row, localizedMessage); } else { tipoError = 2; /* OJO con la constante, 2 -> fila con un error conocido */ mensaje = tipoError + TLC.getBitacora().error(clave, transaction, prefijo + row); } } } this.getFilasConflictivas().put(String.valueOf(row - 1), mensaje); // if (status == SyncResolver.DELETE_ROW_CONFLICT) // if (this.absolute(row)) // if (this.rowDeleted()) // RETORNA FALSO! // this.undoDelete(); } if (conflictos == 0) { /* esto parece un BUG, y pasa cuando se elimina la ultima fila y showDeleted==false */ TLC.getBitacora().error(clave, transaction, "", spe.getLocalizedMessage()); } } catch (SQLException ex) { TLC.getBitacora().fatal(ex); } finally { this.tryToSetShowDeleted(showDeleted); TLC.getBitacora().setSinDuplicados(sinDuplicados); throw new SyncProviderException(this.getSyncProviderExceptionString(spe)); } } throw spe; } }
From source file:org.pentaho.reporting.engine.classic.extensions.datasources.mondrian.AbstractMDXDataFactory.java
public String[] getReferencedFields(final String queryName, final DataRow parameters) throws ReportDataFactoryException { final boolean isNewConnection = connection == null; try {/*from w w w . j a v a2 s.c o m*/ if (connection == null) { connection = mondrianConnectionProvider.createConnection(computeProperties(parameters), dataSourceProvider.getDataSource()); } } catch (SQLException e) { logger.error(e); throw new ReportDataFactoryException("Failed to create DataSource (SQL Exception - error code: " + e.getErrorCode() + "):" + e.toString(), e); } catch (MondrianException e) { logger.error(e); throw new ReportDataFactoryException("Failed to create DataSource (Mondrian Exception):" + e.toString(), e); } try { if (connection == null) { throw new ReportDataFactoryException("Factory is closed."); } final LinkedHashSet<String> parameter = new LinkedHashSet<String>(); final MDXCompiler compiler = new MDXCompiler(parameters, getLocale()); final String computedQuery = computedQuery(queryName, parameters); final String mdxQuery = compiler.translateAndLookup(computedQuery, parameters); parameter.addAll(compiler.getCollectedParameter()); // Alternatively, JNDI is possible. Maybe even more .. final Query query = connection.parseQuery(mdxQuery); final Parameter[] queryParameters = query.getParameters(); for (int i = 0; i < queryParameters.length; i++) { final Parameter queryParameter = queryParameters[i]; parameter.add(queryParameter.getName()); } if (jdbcUserField != null) { parameter.add(jdbcUserField); } if (roleField != null) { parameter.add(roleField); } parameter.add(DataFactory.QUERY_LIMIT); return parameter.toArray(new String[parameter.size()]); } catch (MondrianException e) { throw new ReportDataFactoryException("Failed to create datasource:" + e.getLocalizedMessage(), e); } finally { if (isNewConnection) { close(); } } }
From source file:ips1ap101.lib.core.db.xdp.RecursoCachedRowSet.java
/** * {@inheritDoc}/*www . j a va 2 s .c o m*/ */ @Override public void acceptChanges() throws SyncProviderException { try { this.getFilasConflictivas().clear(); super.acceptChanges(); } catch (SyncProviderException spe) { SyncResolver resolver = spe.getSyncResolver(); if (resolver != null && resolver instanceof SyncResolverX) { boolean showDeleted = this.tryToGetShowDeleted(); boolean sinDuplicados = TLC.getBitacora().isSinDuplicados(); int conflictos = 0; int row; int status = SyncResolver.NO_ROW_CONFLICT; String transaction = DBUtils.getTransactionLabel(status); SQLException sqlException; int errorCode; String message; String localizedMessage; String sqlState; String clave = CBM.COMMIT_CHANGES_UNKNOWN_EXCEPTION; int tipoError; /* OJO con la constante, 1 -> fila con un error desconocido */ String mensaje; String prefijo = Global.PREFIJO_ETIQUETA_ID_RECURSO; try { this.tryToSetShowDeleted(true); TLC.getBitacora().setSinDuplicados(true); while (resolver.nextConflict()) { conflictos++; row = resolver.getRow(); status = resolver.getStatus(); transaction = DBUtils.getTransactionLabel(status); sqlException = ((SyncResolverX) resolver).getSQLException(); errorCode = sqlException.getErrorCode(); message = sqlException.getMessage(); localizedMessage = DBUtils.getProperErrorMessage(sqlException.getLocalizedMessage()); sqlState = sqlException.getSQLState(); Bitacora.trace("SQLException Message = " + message); Bitacora.trace("SQLException Localized Message = " + localizedMessage); Bitacora.trace("SQLException Row = " + row + ", Status = " + status + ", Code = " + errorCode + ", State = " + sqlState); if (TLC.getInterpreteSql().isCommandIgnoredException(sqlException)) { clave = CBM.COMMIT_CHANGES_COMMAND_IGNORED_EXCEPTION; tipoError = 0; /* OJO con la constante, 0 -> fila "ignorada" (no se sabe si tiene o no errores) */ mensaje = tipoError + Bitacora.getTextoMensaje(clave, transaction, prefijo + row); TLC.getBitacora().error(CBM.COMMIT_CHANGES_COMMAND_IGNORED); if (status == SyncResolver.DELETE_ROW_CONFLICT) { this.tryToSetShowDeleted(false); } } else { String columna = TLC.getInterpreteSql() .getNotNullConstraintViolationColumn(sqlException); if (StringUtils.isNotBlank(columna)) { clave = CBM.DATABASE_NOT_NULL_CONSTRAINT_VIOLATION; tipoError = 2; /* OJO con la constante, 2 -> fila con un error conocido */ mensaje = tipoError + TLC.getBitacora().error(clave, transaction, prefijo + row, columna); } else { clave = DBUtils.getConstraintMessageKey(message, status); if (clave == null) { clave = CBM.COMMIT_CHANGES_UNKNOWN_EXCEPTION; tipoError = 1; /* OJO con la constante, 1 -> fila con un error desconocido */ mensaje = tipoError + TLC.getBitacora().error(clave, transaction, prefijo + row, localizedMessage); } else { tipoError = 2; /* OJO con la constante, 2 -> fila con un error conocido */ mensaje = tipoError + TLC.getBitacora().error(clave, transaction, prefijo + row); } } } this.getFilasConflictivas().put(String.valueOf(row - 1), mensaje); // if (status == SyncResolver.DELETE_ROW_CONFLICT) // if (this.absolute(row)) // if (this.rowDeleted()) // RETORNA FALSO! // this.undoDelete(); } if (conflictos == 0) { /* esto parece un BUG, y pasa cuando se elimina la ultima fila y showDeleted==false */ TLC.getBitacora().error(clave, transaction, "", spe.getLocalizedMessage()); } } catch (SQLException ex) { TLC.getBitacora().fatal(ex); } finally { this.tryToSetShowDeleted(showDeleted); TLC.getBitacora().setSinDuplicados(sinDuplicados); throw new SyncProviderException(this.getSyncProviderExceptionString(spe)); } } throw spe; } }
From source file:it.fub.jardin.server.DbUtils.java
/** * @param tableName//from w ww . ja v a 2s. c o m * @param fieldName * @return Lista dei valori per quel determinato campo di quell determinata * tabella. Serve a riempire i combobox per la modifica della griglia * @throws HiddenException * @throws SQLException */ public List<BaseModelData> getValuesOfAFieldFromTableName(final String tableName, final String fieldName) throws HiddenException { try { return this.getValuesOfAField("`" + tableName + "`", fieldName); } catch (SQLException e) { e.printStackTrace(); throw new HiddenException("Errore con i valori della chiave primaria " + e.getLocalizedMessage()); } }