Example usage for java.sql SQLException getLocalizedMessage

List of usage examples for java.sql SQLException getLocalizedMessage

Introduction

In this page you can find the example usage for java.sql SQLException getLocalizedMessage.

Prototype

public String getLocalizedMessage() 

Source Link

Document

Creates a localized description of this throwable.

Usage

From source file:de.tu_berlin.dima.oligos.Oligos.java

public static void main(String[] args) throws TypeNotSupportedException {
    BasicConfigurator.configure();//from  www .  ja  va  2 s .co m

    // TODO create cmdline option for setting logger level
    Logger.getRootLogger().setLevel(Level.INFO);
    CommandLineInterface cli = new CommandLineInterface(args);
    try {
        // TODO hard exit if the parsing fails!
        // better catch exceptions and log them
        if (!cli.parse()) {
            System.exit(2);
        }

        Properties props = new Properties();
        props.setProperty("user", cli.getUsername());
        props.setProperty("password", cli.getPassword());
        Connection connection = DriverManager.getConnection(cli.getConnectionString(), props);
        JdbcConnector jdbcConnector = new JdbcConnector(connection);
        MetaConnector metaConnector = null;
        Driver dbDriver = cli.dbDriver;
        switch (dbDriver.driverName) {
        case db2:
            LOGGER.trace("metaConnector = Db2MetaConnector");
            metaConnector = new Db2MetaConnector(jdbcConnector);
            break;
        case oracle:
            metaConnector = new OracleMetaConnector(jdbcConnector);
            break;
        default:
            LOGGER.error("Unknown database driver. Supported drivers are: " + DriverName.values());
        }

        // validating schema
        LOGGER.info("Validating input schema ...");
        SparseSchema sparseSchema = cli.getInputSchema();
        LOGGER.trace("User specified schema " + sparseSchema);
        DenseSchema inputSchema = DbUtils.populateSchema(sparseSchema, jdbcConnector, metaConnector);
        LOGGER.trace("Populated and validated schema " + inputSchema);

        // obtaining type information/ column meta data
        LOGGER.info("Retrieving column meta data ...");
        Map<ColumnId, TypeInfo> columnTypes = Maps.newLinkedHashMap();
        for (ColumnId columnId : inputSchema) {
            TypeInfo type = metaConnector.getColumnType(columnId);
            columnTypes.put(columnId, type);
        }

        // creating connectors and profilers
        LOGGER.info("Establashing database connection ...");
        SchemaConnector schemaConnector = null;
        TableConnector tableConnector = null;
        switch (dbDriver.driverName) {
        case db2:
            schemaConnector = new Db2SchemaConnector(jdbcConnector);
            tableConnector = new Db2TableConnector(jdbcConnector);
            break;
        case oracle:
            schemaConnector = new OracleSchemaConnector(jdbcConnector);
            tableConnector = new OracleTableConnector(jdbcConnector);
        }
        Set<SchemaProfiler> profilers = Sets.newLinkedHashSet();
        for (String schema : inputSchema.schemas()) {
            SchemaProfiler schemaProfiler = new SchemaProfiler(schema, schemaConnector);
            profilers.add(schemaProfiler);
            for (String table : inputSchema.tablesIn(schema)) {
                TableProfiler tableProfiler = new TableProfiler(schema, table, tableConnector);
                schemaProfiler.add(tableProfiler);
                for (String column : inputSchema.columnsIn(schema, table)) {
                    ColumnId columnId = new ColumnId(schema, table, column);
                    TypeInfo type = columnTypes.get(columnId);
                    ColumnProfiler<?> columnProfiler = null;
                    switch (dbDriver.driverName) {
                    case db2:
                        columnProfiler = getProfiler(schema, table, column, type, jdbcConnector, metaConnector);
                        break;
                    case oracle:
                        columnProfiler = getProfilerOracle(schema, table, column, type, jdbcConnector,
                                metaConnector);
                    }
                    tableProfiler.addColumnProfiler(columnProfiler);
                }
            }
        }
        // profiling statistical data
        LOGGER.info("Profiling schema ...");
        Set<Schema> profiledSchemas = Sets.newLinkedHashSet();
        for (SchemaProfiler schemaProfiler : profilers) {
            Schema profiledSchema = schemaProfiler.profile();
            profiledSchemas.add(profiledSchema);
        }

        LOGGER.info("Generating generator specification ...");
        File outputDir = cli.getOutputDirectory();
        String generatorName = cli.getGeneratorName();
        LOGGER.info("Writing generator specification ...");
        for (Schema schema : profiledSchemas) {
            MyriadWriter writer = new MyriadWriter(schema, outputDir, generatorName);
            writer.write();
        }
        LOGGER.info("Closing database connection ...");
        connection.close();
    } catch (SQLException e) {
        LOGGER.error(e.getLocalizedMessage());
        LOGGER.debug(ExceptionUtils.getStackTrace(e));
    } catch (IOException e) {
        LOGGER.error(e.getLocalizedMessage());
        LOGGER.debug(ExceptionUtils.getStackTrace(e));
    } catch (ParseException e) {
        LOGGER.error(e.getMessage());
        cli.printHelpMessage();
    }
}

From source file:org.opencms.db.oracle.CmsSqlManager.java

/**
 * Attempts to close the connection, statement and result set after a statement has been executed.<p>
 * /*w  w  w.j ava 2  s .com*/
 * @param sqlManager the sql manager to use
 * @param dbc the current database context
 * @param con the JDBC connection
 * @param stmnt the statement
 * @param res the result set
 * @param commit the additional statement for the 'commit' command
 * @param wasInTransaction if using transactions
 */
public static synchronized void closeAllInTransaction(org.opencms.db.generic.CmsSqlManager sqlManager,
        CmsDbContext dbc, Connection con, PreparedStatement stmnt, ResultSet res, PreparedStatement commit,
        boolean wasInTransaction) {

    if (dbc == null) {
        LOG.error(Messages.get().getBundle().key(Messages.LOG_NULL_DB_CONTEXT_0));
    }

    if (res != null) {
        try {
            res.close();
        } catch (SQLException exc) {
            // ignore
            if (LOG.isDebugEnabled()) {
                LOG.debug(exc.getLocalizedMessage(), exc);
            }
        }
    }
    if (commit != null) {
        try {
            commit.close();
        } catch (SQLException exc) {
            // ignore
            if (LOG.isDebugEnabled()) {
                LOG.debug(exc.getLocalizedMessage(), exc);
            }
        }
    }
    if (!wasInTransaction) {
        if (stmnt != null) {
            try {
                PreparedStatement rollback = sqlManager.getPreparedStatement(con, "C_ROLLBACK");
                rollback.execute();
                rollback.close();
            } catch (SQLException se) {
                // ignore
                if (LOG.isDebugEnabled()) {
                    LOG.debug(se.getLocalizedMessage(), se);
                }
            }
            try {
                stmnt.close();
            } catch (SQLException exc) {
                // ignore
                if (LOG.isDebugEnabled()) {
                    LOG.debug(exc.getLocalizedMessage(), exc);
                }
            }
        }
        if (con != null) {
            try {
                con.setAutoCommit(true);
                con.close();
            } catch (SQLException se) {
                // ignore
                if (LOG.isDebugEnabled()) {
                    LOG.debug(se.getLocalizedMessage(), se);
                }
            }
        }
    }
}

From source file:com.ibm.research.rdf.store.runtime.service.sql.UpdateHelper.java

private static String executeCall(Connection conn, String sql, int retPid, Object... params) {

    CallableStatement stmt = null;
    String ret = null;/* w  ww.ja  va  2  s .co  m*/

    try {
        conn.setAutoCommit(false);
    } catch (SQLException ex) {
        log.error(ex);
        ex.printStackTrace();
        System.out.println(ex.getLocalizedMessage());
        return ret;
    }

    try {

        stmt = conn.prepareCall(sql);
        int i = 1;
        for (Object o : params) {
            stmt.setObject(i, o);
            i++;
        }

        stmt.registerOutParameter(retPid, Types.VARCHAR);

        stmt.execute();
        ret = stmt.getString(retPid);

        conn.commit();

    } catch (SQLException e) {
        //         log.error(e);
        //         e.printStackTrace();
        //         System.out.println(e.getLocalizedMessage());
        ret = null;

        try {
            conn.rollback();
        } catch (SQLException e1) {
            // TODO Auto-generated catch block
            log.error(e1);
            e1.printStackTrace();
            System.out.println(e1.getLocalizedMessage());
            ret = null;
        }

    } finally {
        closeSQLObjects(stmt, null);
    }

    try {
        conn.setAutoCommit(true);
    } catch (SQLException ex) {
        log.error(ex);
        ex.printStackTrace();
        System.out.println(ex.getLocalizedMessage());
        ret = null;
    }

    return ret;
}

From source file:com.ibm.research.rdf.store.runtime.service.sql.StoreHelper.java

public static void setPath(Connection conn, String schemaName) {

    if (schemaName != null && schemaName.length() > 0) {
        try {/*from ww  w  .java 2s  .c  om*/

            // set even the CURRENT PATH... this is for UDF's
            SQLExecutor.executeUpdate(conn, "set current path = " + schemaName + ",current path");
        } catch (SQLExceptionWrapper e) {
            SQLException e1 = (SQLException) e.getCause();
            if (e1.getErrorCode() == -585) {
                // duplicate schema, no action required
                return;
            }
            throw new RdfStoreException(e1.getLocalizedMessage(), e1);
        }

    }
}

From source file:com.ibm.research.rdf.store.jena.impl.DB2TransactionHandler.java

public void abort() {
    try {//from ww  w .  j  ava2  s. c  o m
        conn.rollback();
    } catch (SQLException e) {
        log.error("Cannot abort transaction", e);
        throw new RdfStoreException(e.getLocalizedMessage(), e);
    }
}

From source file:com.ibm.research.rdf.store.jena.impl.DB2TransactionHandler.java

public void begin() {
    try {/*from   w w  w  .j  a va2s  .co m*/
        conn.setAutoCommit(false);
    } catch (SQLException e) {
        log.error("Cannot begin transaction", e);
        throw new RdfStoreException(e.getLocalizedMessage(), e);
    }
}

From source file:com.ibm.research.rdf.store.jena.impl.DB2TransactionHandler.java

public void commit() {
    try {//  w w  w. jav a 2s .co  m
        conn.commit();
    } catch (SQLException e) {
        log.error("Cannot commit transaction", e);
        throw new RdfStoreException(e.getLocalizedMessage(), e);
    }
}

From source file:com.alkacon.opencms.formgenerator.database.CmsFormDatabaseModuleAction.java

/**
 * @see org.opencms.module.A_CmsModuleAction#initialize(org.opencms.file.CmsObject, org.opencms.configuration.CmsConfigurationManager, org.opencms.module.CmsModule)
 *///  w  ww.j a v  a2 s.  c o  m
@Override
public void initialize(CmsObject adminCms, CmsConfigurationManager configurationManager, CmsModule module) {

    super.initialize(adminCms, configurationManager, module);
    try {
        CmsFormDataAccess.getInstance().setCms(adminCms);
        CmsFormDataAccess.getInstance().ensureDBTablesExistance();
    } catch (SQLException sqlex) {
        if (LOG.isErrorEnabled()) {
            LOG.error(sqlex.getLocalizedMessage(), sqlex);
        }
    }
}

From source file:org.wso2.carbon.attachment.mgt.core.datasource.impl.JDBCManager.java

@Override
public void shutdown() throws AttachmentMgtException {
    try {//from  www  . j a  v  a  2s. co m
        dataSource.close();
        dataSource = null;
    } catch (SQLException e) {
        throw new AttachmentMgtException(e.getLocalizedMessage(), e);
    }
}

From source file:org.deegree.db.legacy.LegacyConnectionProvider.java

@Override
public Connection getConnection() {
    try {//from   w  ww.j  a v a2 s.c om
        return pool.getConnection();
    } catch (SQLException e) {
        throw new ResourceException(e.getLocalizedMessage(), e);
    }
}