Example usage for java.sql SQLException getMessage

List of usage examples for java.sql SQLException getMessage

Introduction

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

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:net.sf.springderby.EmbeddedDataSourceFactory.java

private void shutdown() throws Exception {
    dataSource.setShutdownDatabase("shutdown");
    // getConnection must be called to actually perform the shutdown. Note that this 
    // instruction always throws an exception. We therefore catch SQLExceptions and check
    // for the expected exception type.
    try {//  w  ww.ja  v a  2  s.com
        dataSource.getConnection();
    } catch (SQLException ex) {
        if ("08006".equals(ex.getSQLState())) {
            log.info(ex.getMessage());
        } else {
            throw ex;
        }
    }
    executeOfflineActions(afterShutdownActions);
}

From source file:com.cws.us.pws.processors.impl.CareerReferenceImpl.java

/**
 * @see com.cws.us.pws.processors.interfaces.ICareerReference#getProductData(CareerRequest)
 *//*from ww w. j  ava 2s.c o m*/
@Override
public CareerResponse getCareerData(final CareerRequest request) throws CareerRequestException {
    final String methodName = ICareerReference.CNAME
            + "#getCareerData(final CareerRequest request) throws CareerRequestException";

    if (DEBUG) {
        DEBUGGER.debug(methodName);
        DEBUGGER.debug("request: {}", request);
    }

    CareerResponse response = new CareerResponse();

    final Career reqCareer = request.getCareer();

    if (DEBUG) {
        DEBUGGER.debug("Career: {}", reqCareer);
    }

    if (reqCareer != null) {
        try {
            List<Object> careerData = this.dao.getCareerData(reqCareer.getJobReqId(), request.getLang());

            if (DEBUG) {
                DEBUGGER.debug("careerData: {}", careerData);
            }

            if ((careerData != null) && (careerData.size() != 0)) {
                Career career = new Career();
                career.setJobReqId((String) careerData.get(0));
                career.setPostDate((Date) careerData.get(1));
                career.setUnpostDate((Date) careerData.get(2));
                career.setJobTitle((String) careerData.get(3));
                career.setJobShortDesc((String) careerData.get(4));
                career.setJobDescription((String) careerData.get(5));

                if (DEBUG) {
                    DEBUGGER.debug("Career: {}", career);
                }

                response.setRequestStatus(CoreServicesStatus.SUCCESS);
                response.setResponse("Successfully loaded product " + reqCareer.getJobReqId());
                response.setCareer(career);
            } else {
                response.setRequestStatus(CoreServicesStatus.FAILURE);
                response.setResponse("Failed to load career with ID " + reqCareer.getJobReqId());
            }

            if (DEBUG) {
                DEBUGGER.debug("CareerResponse: {}", response);
            }
        } catch (SQLException sqx) {
            ERROR_RECORDER.error(sqx.getMessage(), sqx);

            throw new CareerRequestException(sqx.getMessage(), sqx);
        }
    } else {
        throw new CareerRequestException("No product data was provided. Unable to continue");
    }

    return response;
}

From source file:org.elasticsearch.xpack.qa.sql.jdbc.ErrorsTestCase.java

@Override
public void testSelectScoreInScalar() throws Exception {
    index("test", body -> body.field("foo", 1));
    try (Connection c = esJdbc()) {
        SQLException e = expectThrows(SQLException.class,
                () -> c.prepareStatement("SELECT SIN(SCORE()) FROM test").executeQuery());
        assertThat(e.getMessage(),
                startsWith("Found 1 problem(s)\nline 1:12: [SCORE()] cannot be an argument to a function"));
    }/*from  w  w w.ja  va2  s  .c om*/
}

From source file:ips1ap101.lib.core.db.util.InterpreteSqlPostgreSQL.java

@Override
public boolean isCommandIgnoredException(SQLException sqle) {
    String string = sqle == null ? null : sqle.getMessage();
    return string != null && contains(string, command_ignored);
}

From source file:IDlook.java

public void connectToDB() {
    try {/*  w w w .j a v a2 s .  co  m*/
        connection = DriverManager
                .getConnection("jdbc:mysql://192.168.1.25/identification?user=spider&password=spider");
        statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);

    } catch (SQLException connectException) {
        System.out.println(connectException.getMessage());
        System.out.println(connectException.getSQLState());
        System.out.println(connectException.getErrorCode());
        System.exit(1);
    }
}

From source file:edu.lternet.pasta.dml.database.SimpleDatabaseLoader.java

/**
 * Determines whether the data table /* w w  w .j  a va2 s .c  om*/
 * already exists in the database and is loaded with data. This method is
 * mandated by the DataStorageInterface.
 * 
 * First, check that the data table exists. Second, check that the row count
 * is greater than zero. (We want to make sure that the table has not only
 * been created, but has also been loaded with data.)
 * 
 * @param identifier
 *            the identifier for the data table
 * @return true if the data table has been loaded into the database, else
 *         false
 */
public boolean doesDataExist(String identifier) {
    boolean doesExist = false;

    try {
        String tableName = tableMonitor.identifierToTableName(identifier);
        doesExist = tableMonitor.isTableInDB(tableName);

        if (doesExist) {
            int rowCount = tableMonitor.countRows(tableName);
            doesExist = (rowCount > 0);
        }
    } catch (SQLException e) {
        log.error(e.getMessage());
        e.printStackTrace();
    }

    return doesExist;
}

From source file:net.hydromatic.foodbench.Main.java

/** Does the work. */
private void run(String jdbcUrl, String catalog, String driverClassName)
        throws IOException, SQLException, ClassNotFoundException {
    URL url = FoodMartQuery.class.getResource("/queries.json");
    InputStream inputStream = url.openStream();
    ObjectMapper mapper = new ObjectMapper();
    Map values = mapper.readValue(inputStream, Map.class);
    //noinspection unchecked
    List<Map<String, Object>> tests = (List) values.get("queries");
    if (driverClassName != null) {
        Class.forName(driverClassName);
    }/*from w w w  .ja va 2 s .c  o  m*/
    Connection connection = DriverManager.getConnection(jdbcUrl);
    if (catalog != null) {
        connection.setCatalog(catalog);
    }
    Statement statement = connection.createStatement();
    for (Map<String, Object> test : tests) {
        int id = (Integer) test.get("id");
        if (!idSet.contains(id)) {
            continue;
        }
        String sql = (String) test.get("sql");
        if (jdbcUrl.startsWith("jdbc:mysql:")) {
            sql = sql.replace("\"", "`");
            sql = sql.replace(" NULLS FIRST", "");
            sql = sql.replace(" NULLS LAST", "");
            if (sql.contains("VALUES ")) {
                System.out.println("query id: " + id + " sql: " + sql + " skipped");
                continue;
            }
        }
        if (jdbcUrl.startsWith("jdbc:optiq:")) {
            sql = sql.replace("RTRIM(", "TRIM(TRAILING ' ' FROM ");
        }
        final AtomicLong tPrepare = new AtomicLong(0);
        Hook.Closeable hook = Hook.JAVA_PLAN.add(new Function1<Object, Object>() {
            public Object apply(Object a0) {
                tPrepare.set(System.nanoTime());
                return null;
            }
        });
        try {
            final long t0 = System.nanoTime();
            ResultSet resultSet = statement.executeQuery(sql);
            int n = 0;
            while (resultSet.next()) {
                ++n;
            }
            resultSet.close();
            final long tEnd = System.nanoTime();
            final long nanos = tEnd - t0;
            final long prepare = tPrepare.longValue() - t0;
            final long execute = tEnd - tPrepare.longValue();
            System.out.println("query id: " + id + " rows: " + n + " nanos: " + NF.format(nanos) + " prepare: "
                    + NF.format(prepare) + " execute: " + NF.format(execute) + " prepare%: "
                    + ((float) prepare / (float) nanos * 100f));
        } catch (SQLException e) {
            System.out.println("query id: " + id + " sql: " + sql + " error: " + e.getMessage());
            if (verbose) {
                e.printStackTrace();
            }
        } finally {
            hook.close();
        }
    }
    statement.close();
    connection.close();
}

From source file:com.reydentx.core.client.MySQLClient.java

public void rollback(Connection client) {
    try {/*from  w w w  .j a v  a  2  s.  c om*/
        client.rollback();
    } catch (SQLException ex) {
        _logger.error(ex.getMessage(), ex);
    }
}

From source file:MyStatsPanel.java

void getIDTypesInfo() {
    try {//from   w ww . java  2 s  .  c  o  m
        String SQL_Query = " Select count(*)" + " From Visitation_Detail v" + " Where v.guest_ID_type = 'FSU' ";

        myResultSet = statement.executeQuery(SQL_Query);
        myResultSet.first();
        FSU = myResultSet.getInt(1);
        myResultSet.close();

        SQL_Query = " Select count(*)" + " From Visitation_Detail v" + " Where v.guest_ID_type = 'PCTC' ";

        myResultSet = statement.executeQuery(SQL_Query);
        myResultSet.first();
        PCTC = myResultSet.getInt(1);
        myResultSet.close();

        SQL_Query = " Select count(*)" + " From Visitation_Detail v" + " Where v.guest_ID_type = 'DL' ";

        myResultSet = statement.executeQuery(SQL_Query);
        myResultSet.first();
        DL = myResultSet.getInt(1);
        myResultSet.close();

        SQL_Query = " Select count(*)" + " From Visitation_Detail v" + " Where v.guest_ID_type = 'Other' ";

        myResultSet = statement.executeQuery(SQL_Query);
        myResultSet.first();
        OTHERS = myResultSet.getInt(1);
        myResultSet.close();
    } catch (SQLException sqlException) {
        JOptionPane.showMessageDialog(this, sqlException.getMessage());
    } catch (Exception exception) {
        JOptionPane.showMessageDialog(this, exception.getMessage());
    }
}

From source file:com.dangdang.ddframe.job.event.rdb.JobRdbEventStorage.java

boolean addJobTraceEvent(final JobTraceEvent traceEvent) {
    boolean result = false;
    if (needTrace(traceEvent.getLogLevel())) {
        String sql = "INSERT INTO `job_trace_log` (`id`, `job_name`, `hostname`, `message`, `failure_cause`, `creation_time`) VALUES (?, ?, ?, ?, ?, ?);";
        try (Connection conn = dataSource.getConnection();
                PreparedStatement preparedStatement = conn.prepareStatement(sql)) {
            preparedStatement.setString(1, UUID.randomUUID().toString());
            preparedStatement.setString(2, traceEvent.getJobName());
            preparedStatement.setString(3, traceEvent.getHostname());
            preparedStatement.setString(4, traceEvent.getMessage());
            preparedStatement.setString(5, getFailureCause(traceEvent.getFailureCause()));
            preparedStatement.setTimestamp(6, new Timestamp(traceEvent.getCreationTime().getTime()));
            preparedStatement.execute();
            result = true;/*w w w.j av a2 s.c  om*/
        } catch (final SQLException ex) {
            // TODO ,???
            log.error(ex.getMessage());
        }
    }
    return result;
}