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:com.nextep.designer.sqlgen.mysql.impl.MySQLDatabaseConnector.java

@Override
public void doPostConnectionSettings(IConnection conn, Connection sqlConn) throws SQLException {
    Statement stmt = null;/*w  w  w .j  av  a  2s.co m*/
    try {
        stmt = sqlConn.createStatement();
        stmt.execute("SET CHARACTER SET utf8"); //$NON-NLS-1$
    } catch (SQLException sqle) {
        LOGGER.error("Unable to set the character set: " + sqle.getMessage(), sqle);
        throw sqle;
    } finally {
        CaptureHelper.safeClose(null, stmt);
    }
}

From source file:com.tesora.dve.upgrade.versions.AddCollation.java

@Override
public void upgrade(DBHelper helper, InformationCallback stdout) throws PEException {
    super.upgrade(helper, stdout);

    try {// www  . j a v  a2  s . c om
        List<Object> params = new ArrayList<Object>();

        helper.prepare(
                "insert into collations (id, name, character_set_name, is_default, is_compiled, sortlen) values (?,?,?,?,?,?)");

        for (String collationName : MysqlNativeCollationCatalog.DEFAULT_CATALOG
                .getCollationsCatalogEntriesByName()) {
            NativeCollation nc = MysqlNativeCollationCatalog.DEFAULT_CATALOG.findCollationByName(collationName);
            params.clear();
            params.add(nc.getId());
            params.add(nc.getName());
            params.add(nc.getCharacterSetName());
            params.add(BooleanUtils.toInteger(nc.isDefault()));
            params.add(BooleanUtils.toInteger(nc.isCompiled()));
            params.add(nc.getSortLen());
            helper.executePrepared(params);
        }
    } catch (SQLException sqle) {
        throw new PEException("Unable to insert collation values: " + sqle.getMessage());
    }
}

From source file:com.mycompany.rubricatelefonica.DefaultSmartphoneDao.java

public boolean insertNewSmartphone(SmartphoneModel s) {
    boolean inserito = false;
    MysqlDataSource dataSource = new MysqlDataSource();

    dataSource.setUser("root");
    dataSource.setPassword("root");
    dataSource.setUrl("jdbc:mysql://localhost:3306/RubricaTelef");

    Connection conn = null;/*from w  w  w.  j  a v a2  s .c om*/

    try {

        conn = dataSource.getConnection();

        PreparedStatement stmtInsertSmartph = conn.prepareStatement(INSERT_SMARTPHONE);
        stmtInsertSmartph.setString(1, s.getImei());
        stmtInsertSmartph.setString(2, s.getMarca());
        stmtInsertSmartph.setString(3, s.getModello());
        stmtInsertSmartph.setString(4, s.getAnno());
        stmtInsertSmartph.setString(5, s.getColore());
        stmtInsertSmartph.setString(6, s.getMateriale());
        stmtInsertSmartph.setString(7, s.getSistOp());

        if (stmtInsertSmartph.executeUpdate() > 0) {
            inserito = true;
        }

    } catch (SQLException e) {
        System.out.println(e.getMessage());
        System.out.println("errore!! Connessione Fallita");
    } finally {

        DbUtils.closeQuietly(conn); //oppure try with resource
    }

    return inserito;

}

From source file:jp.primecloud.auto.tool.management.zabbix.ZabbixSqlService.java

public String getUser(String username) throws SQLException, Exception {

    String getUserSql = "select alias from users where alias='" + username + "'";
    String nameResult = "";
    try {/*from ww w  .  ja  v a  2 s  . co  m*/
        Object result = sqlExecuter.getColumn(getUserSql, "alias", "string");
        if (result != null) {
            nameResult = result.toString();
        }
    } catch (SQLException e) {
        log.error(e.getMessage(), e);
        throw new SQLException(e);
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw new Exception(e);
    }
    return nameResult;
}

From source file:com.cws.esolutions.core.dao.impl.ServerDataDAOImplTest.java

@Test
public void addNewServer() {
    List<Object> data = new ArrayList<Object>(Arrays.asList(this.guid, "CentOS", ServiceStatus.ACTIVE.name(),
            ServiceRegion.DEV.name(), ServerType.APPSERVER.name(), "caspersbox.com", "AMD Athlon 1.0 GHz", 1,
            "VPS", RandomStringUtils.randomAlphanumeric(8).toUpperCase(), 512, "127.0.0.1",
            RandomStringUtils.randomAlphanumeric(8).toLowerCase(), "127.0.0.1",
            RandomStringUtils.randomAlphanumeric(8).toLowerCase(), "127.0.0.1",
            RandomStringUtils.randomAlphanumeric(8).toLowerCase(), "127.0.0.1",
            RandomStringUtils.randomAlphanumeric(8).toLowerCase(), "Unconfigured", "JUnit test", "khuntly",
            "Unconfigured", 0, "Unconfigured", "Unconfigured", "Unconfigured"));

    try {//from  w  w w  .j  a v  a2  s  .  c o m
        Assert.assertTrue(dao.addServer(data));
    } catch (SQLException sqx) {
        Assert.fail(sqx.getMessage());
    }
}

From source file:com.cws.esolutions.core.dao.impl.ServerDataDAOImplTest.java

@Test
public void modifyServerData() {
    List<Object> data = new ArrayList<Object>(Arrays.asList(this.guid, "CentOS", ServiceStatus.ACTIVE.name(),
            ServiceRegion.DEV.name(), ServerType.APPSERVER.name(), "caspersbox.com", "AMD Athlon 1.0 GHz", 1,
            "VPS", RandomStringUtils.randomAlphanumeric(8).toUpperCase(), 512, "127.0.0.1",
            RandomStringUtils.randomAlphanumeric(8).toLowerCase(), "127.0.0.1",
            RandomStringUtils.randomAlphanumeric(8).toLowerCase(), "127.0.0.1",
            RandomStringUtils.randomAlphanumeric(8).toLowerCase(), "127.0.0.1",
            RandomStringUtils.randomAlphanumeric(8).toLowerCase(), "Unconfigured", "JUnit test", "khuntly",
            "Unconfigured", 0, "Unconfigured", "Unconfigured", "Unconfigured"));

    try {// w w w .j  ava  2  s  .  co  m
        Assert.assertNotNull(dao.updateServer("DMGRSERVER", data));
    } catch (SQLException sqx) {
        Assert.fail(sqx.getMessage());
    }
}

From source file:eionet.meta.ContainerContextClosedHandler.java

/**
 * Unregisters mysql connections.//  w  w  w.  ja v  a  2  s. c  o  m
 *
 * @param servletContextEvent
 *            servlet context
 */
@Override
public void contextDestroyed(ServletContextEvent servletContextEvent) {
    Enumeration<Driver> drivers = DriverManager.getDrivers();

    Driver driver = null;

    // clear drivers
    while (drivers.hasMoreElements()) {
        try {
            driver = drivers.nextElement();
            DriverManager.deregisterDriver(driver);
        } catch (SQLException ex) {
            // deregistration failed
            LOGGER.warn(ex.getMessage());
        }
    }

    // MySQL driver leaves around a thread. This static method cleans it up.
    try {
        // throw new InterruptedException();
        AbandonedConnectionCleanupThread.shutdown();
    } catch (InterruptedException ex) {
        // again failure
        LOGGER.warn(ex.getMessage());
    }
}

From source file:org.camunda.bpm.spring.boot.starter.configuration.impl.custom.EnterLicenseKeyConfiguration.java

@Override
public void postProcessEngineBuild(ProcessEngine processEngine) {
    if (!version.isEnterprise()) {
        return;//from   www . ja v a 2  s. c  o  m
    }

    URL fileUrl = camundaBpmProperties.getLicenseFile();

    Optional<String> licenseKey = readLicenseKeyFromUrl(fileUrl);
    if (!licenseKey.isPresent()) {
        fileUrl = EnterLicenseKeyConfiguration.class.getClassLoader().getResource(defaultLicenseFile);
        licenseKey = readLicenseKeyFromUrl(fileUrl);
    }

    if (!licenseKey.isPresent()) {
        return;
    }

    try (Connection connection = dataSource(processEngine).getConnection()) {
        if (readLicenseKeyFromDatasource(connection).isPresent()) {
            return;
        }
        try (PreparedStatement statement = connection.prepareStatement(getSql(INSERT_SQL))) {
            statement.setString(1, licenseKey.get());
            statement.execute();
            LOG.enterLicenseKey(fileUrl);
        }
    } catch (SQLException ex) {
        throw new CamundaBpmNestedRuntimeException(ex.getMessage(), ex);
    }
}

From source file:com.hortonworks.streamline.storage.tool.SQLScriptRunner.java

public boolean checkConnection() {
    try (Connection connection = connect()) {
        return true;
    } catch (SQLException e) {
        System.out.println("Connection failure: " + e.getMessage());
        return false;
    }/*from  w  w w . j a  v  a2  s. c om*/
}

From source file:com.mycompany.rubricatelefonica.DefaultSmartphoneDao.java

public SmartphoneModel getSmartphoneInfo(String imei) {

    SmartphoneModel smartphoneModel = new SmartphoneModel();

    MysqlDataSource dataSource = new MysqlDataSource();

    dataSource.setUser("root");
    dataSource.setPassword("root");
    dataSource.setUrl("jdbc:mysql://localhost:3306/RubricaTelef");

    Connection conn = null;//from   w  w w  . ja v  a2 s.c  om

    try {

        conn = dataSource.getConnection();

        PreparedStatement stmtUserInfo = conn.prepareStatement(SMARTPHONE_INFO);

        stmtUserInfo.setString(1, imei);

        ResultSet rsUserInfoSet = stmtUserInfo.executeQuery();

        if (rsUserInfoSet.first()) {

            smartphoneModel = new SmartphoneModel();
            smartphoneModel.setMarca(rsUserInfoSet.getString("marca"));
            smartphoneModel.setModello(rsUserInfoSet.getString("modello"));
            smartphoneModel.setColore(rsUserInfoSet.getString("colore"));
            smartphoneModel.setMateriale(rsUserInfoSet.getString("materiale"));

        }

    } catch (SQLException e) {
        System.out.println(e.getMessage());
        System.out.println("errore!!");
    } finally {

        DbUtils.closeQuietly(conn); //oppure try with resource
    }

    return smartphoneModel;
}