Example usage for java.sql SQLException toString

List of usage examples for java.sql SQLException toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:org.artifactory.storage.db.build.dao.BuildsDao.java

/**
 * get build props row count// w  w  w  .  ja  va  2 s  . c  om
 *
 * @return
 */
public long getBuildPropsCounts(BuildParams buildParams) {
    ResultSet rs = null;
    try {
        Object[] diffParams = getBuildPropsParam(buildParams);
        String buildQuery = getPropsQueryCounts(buildParams);
        rs = jdbcHelper.executeSelect(buildQuery, diffParams);
        if (rs.next()) {
            return rs.getLong(1);
        }
    } catch (SQLException e) {
        log.error(e.toString());
    } finally {
        DbUtils.close(rs);
    }
    return 0;
}

From source file:org.artifactory.storage.db.build.dao.BuildsDao.java

/**
 * get total published modules count//from  w w w .  ja v a2  s  . c  o m
 *
 * @param buildName - build name
 * @param date      - date
 * @return num of total published modules
 */
public int getPublishedModulesCounts(String buildName, String date) {
    ResultSet rs = null;
    String buildQuery = "SELECT count(*) as cnt FROM build_modules\n"
            + "left join builds on builds.build_id=build_modules.build_id \n"
            + "where  builds.build_number=? and builds.build_date=?";
    try {
        rs = jdbcHelper.executeSelect(buildQuery, buildName, date);
        if (rs.next()) {
            return rs.getInt(1);
        }
    } catch (SQLException e) {
        log.error(e.toString());
    } finally {
        DbUtils.close(rs);
    }
    return 0;
}

From source file:org.artifactory.storage.db.build.dao.BuildsDao.java

/**
 * get Module Artifact diff total Count/*from  w  w w. j ava  2s.  co  m*/
 *
 * @param offset - row offset
 * @param limit  - row limit
 * @return
 */
public List<BuildProps> getBuildProps(BuildParams buildParams, String offset, String limit, String orderBy) {
    ResultSet rs = null;
    List<BuildProps> buildPropsList = new ArrayList<>();
    try {
        String baseQuery;
        Object[] diffParams = getBuildPropsParam(buildParams);
        String buildQuery = getPropsQuery(buildParams);
        rs = jdbcHelper.executeSelect(buildQuery, diffParams);
        while (rs.next()) {
            buildPropsList.add(new BuildProps(rs.getString(1), rs.getString(2), null));
        }
    } catch (SQLException e) {
        log.error(e.toString());
    } finally {
        DbUtils.close(rs);
    }
    return buildPropsList;
}

From source file:org.artifactory.storage.db.build.dao.BuildsDao.java

/**
 * get Module Artifact diff total Count//ww w .ja  v a  2 s .  c  o  m
 *
 * @param buildParams - encapsulate build diff query param
 * @return
 */
public int getPropsDiffCount(BuildParams buildParams) {
    ResultSet rs = null;
    try {
        String baseQuery;
        Object[] diffParams = { buildParams.getCurrBuildNum(), buildParams.getCurrBuildDate(),
                buildParams.getCurrBuildNum(), buildParams.getCurrBuildDate(),
                buildParams.getComperedBuildNum(), buildParams.getComperedBuildDate() };
        String buildQuery = BuildQueries.BUILD_PROPS_COUNT;
        rs = jdbcHelper.executeSelect(buildQuery, diffParams);
        if (rs.next()) {
            return rs.getInt(1);
        }
    } catch (SQLException e) {
        log.error(e.toString());
    } finally {
        DbUtils.close(rs);
    }
    return 0;
}

From source file:com.gdo.sql.slot.SQLSlot.java

/**
 * Method to complete the stencil from SQL values (by default all stencils
 * must have a sql context, so it will be plugged).
 * //from   ww  w. j a  va2  s . c om
 * @param stclContext
 *            the stencil context.
 * @param stencil
 *            the created stencil.
 * @param rs
 *            the result set of values.
 * @param self
 *            this slot as a plugged slot.
 * @return the completion result.
 */
public Result completeStencil(StclContext stclContext, PStcl stencil, ResultSet rs,
        PSlot<StclContext, PStcl> self) {

    // completes at least id
    try {
        stencil.setString(stclContext, Slot.ID, rs.getString(Slot.ID));
    } catch (SQLException e) {
        logWarn(stclContext, e.toString());
    }

    // plugs SQL context
    PStcl sqlContext = self.getContainer().getStencil(stclContext, SQLStcl.Slot.SQL_CONTEXT);
    stencil.plug(stclContext, sqlContext, SQLStcl.Slot.SQL_CONTEXT);

    return Result.success();
}

From source file:org.cerberus.crud.dao.impl.TestCaseCountryPropertiesDAO.java

@Override
public Answer createTestCaseCountryPropertiesBatch(List<TestCaseCountryProperties> listOfPropertiesToInsert) {
    Answer answer = new Answer();
    MessageEvent rs = null;//from  w  w  w.j  a v  a  2  s. c o m
    StringBuilder query = new StringBuilder();
    query.append(
            "INSERT INTO testcasecountryproperties (`Test`,`TestCase`,`Country`,`Property` , `Description`, `Type`");
    query.append(",`Database`,`Value1`,`Value2`,`Length`,`RowLimit`,`Nature`,`RetryNb`,`RetryPeriod`) ");
    query.append("VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)");

    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(query.toString());
        try {
            for (TestCaseCountryProperties prop : listOfPropertiesToInsert) {
                preStat.setString(1, prop.getTest());
                preStat.setString(2, prop.getTestCase());
                preStat.setString(3, prop.getCountry());
                preStat.setString(4, prop.getProperty());
                preStat.setString(5, prop.getDescription());
                preStat.setString(6, prop.getType());
                preStat.setString(7, prop.getDatabase());
                preStat.setString(8, prop.getValue1());
                preStat.setString(9, prop.getValue2());
                preStat.setInt(10, prop.getLength());
                preStat.setInt(11, prop.getRowLimit());
                preStat.setString(12, prop.getNature());
                preStat.setInt(13, prop.getRetryNb());
                preStat.setInt(14, prop.getRetryPeriod());

                preStat.addBatch();
            }

            //executes the batch         
            preStat.executeBatch();

            int affectedRows[] = preStat.executeBatch();

            //verify if some of the statements failed
            boolean someFailed = ArrayUtils.contains(affectedRows, 0)
                    || ArrayUtils.contains(affectedRows, Statement.EXECUTE_FAILED);

            if (someFailed == false) {
                rs = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
                rs.setDescription(
                        rs.getDescription().replace("%ITEM%", "Property").replace("%OPERATION%", "CREATE"));
            } else {
                rs = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
                rs.setDescription(rs.getDescription().replace("%ITEM%", "Property")
                        .replace("%OPERATION%", "CREATE")
                        .replace("%REASON%", "Some problem occurred while creating the new property! "));
            }

        } catch (SQLException exception) {
            rs = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
            rs.setDescription(
                    rs.getDescription().replace("%DESCRIPTION%", "It was not possible to update table."));
            LOG.error("Unable to execute query : " + exception.toString());
        } finally {
            if (preStat != null) {
                preStat.close();
            }
        }
    } catch (SQLException exception) {
        rs = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
        rs.setDescription(rs.getDescription().replace("%DESCRIPTION%", "It was not possible to update table."));
        LOG.error("Unable to execute query : " + exception.toString());
    } finally {
        try {
            if (!this.databaseSpring.isOnTransaction()) {
                if (connection != null) {
                    connection.close();
                }
            }
        } catch (SQLException e) {
            LOG.warn(e.toString());
        }
    }

    answer.setResultMessage(rs);
    return answer;
}

From source file:org.artifactory.storage.db.build.dao.BuildsDao.java

/**
 * get build props diff with another build
 *
 * @return - list of build props with diff status
 */// w w w  . j  a  v a  2 s.  c o  m
public List<BuildProps> diffBuildProps(BuildParams buildParams, String offset, String limit) {
    ResultSet rs = null;
    List<BuildProps> buildPropsList = new ArrayList<>();
    try {
        Object[] diffParams = { buildParams.getComperedBuildNum(), buildParams.getComperedBuildDate(),
                buildParams.getCurrBuildNum(), buildParams.getCurrBuildDate(), buildParams.getCurrBuildNum(),
                buildParams.getCurrBuildDate(), buildParams.getComperedBuildNum(),
                buildParams.getComperedBuildDate(), buildParams.getCurrBuildNum(),
                buildParams.getCurrBuildDate(), buildParams.getComperedBuildNum(),
                buildParams.getComperedBuildDate(), buildParams.getCurrBuildNum(),
                buildParams.getCurrBuildDate(), buildParams.getComperedBuildNum(),
                buildParams.getComperedBuildDate() };
        String buildQuery = BuildQueries.BUILD_PROPS_DIFF;
        rs = jdbcHelper.executeSelect(buildQuery, diffParams);
        while (rs.next()) {
            BuildProps buildProps = new BuildProps(rs.getString(1), rs.getString(2), rs.getString(3));
            buildProps.setPrevValue(rs.getString(4));
            buildPropsList.add(buildProps);
        }
    } catch (SQLException e) {
        log.error(e.toString());
    } finally {
        DbUtils.close(rs);
    }
    return buildPropsList;
}

From source file:org.artifactory.storage.db.build.dao.BuildsDao.java

/**
 * get Module Artifact diff total Count//from  w  w  w.j  a v a  2 s.c  o  m
 *
 * @param offset - row offset
 * @param limit  - row limit
 * @return
 */
public int getModuleDependencyForDiffCount(BuildParams buildParams, String offset, String limit) {
    ResultSet rs = null;
    String baseQuery;
    try {
        baseQuery = getBuildDependencyCountQuery(buildParams);
        Object[] diffParams = getBuildDependencyCountParam(buildParams);
        StringBuilder builder = new StringBuilder(baseQuery);
        if (buildParams.isExcludeInternalDependencies()) {
            // exclude internal dependencies
            builder.append(
                    "where dependency_name_id not in (select build_modules.module_name_id  from build_modules \n"
                            + "inner join builds on builds.build_id = build_modules.build_id\n"
                            + " where builds.build_number=? and builds.build_date=?)");
        }
        String buildQuery = builder.toString();
        rs = jdbcHelper.executeSelect(buildQuery, diffParams);
        if (rs.next()) {
            return rs.getInt(1);
        }
    } catch (SQLException e) {
        log.error(e.toString());
    } finally {
        DbUtils.close(rs);
    }
    return 0;
}

From source file:org.artifactory.storage.db.build.dao.BuildsDao.java

/**
 * get Module Artifact diff with paging/*from  ww  w. ja  va2 s  .  c o m*/
 *
 * @param offset - row offset
 * @param limit  - row limit
 * @return
 */
public List<ModuleArtifact> getModuleArtifactsForDiffWithPaging(BuildParams buildParams, String offset,
        String limit) {
    ResultSet rs = null;
    List<ModuleArtifact> artifacts = new ArrayList<>();
    Map<String, ModuleArtifact> artifactMap = new HashMap<>();
    ResultSet rsArtCurr = null;
    ResultSet rsArtPrev = null;
    try {
        Object[] diffParams = getArtifatBuildQueryParam(buildParams);
        String buildQuery = getArtifactBuildDiffQuery(buildParams);
        rs = jdbcHelper.executeSelect(buildQuery, diffParams);
        while (rs.next()) {
            ModuleArtifact artifact = new ModuleArtifact(null, null, rs.getString(1), rs.getString(2),
                    rs.getString(3));
            artifact.setStatus(rs.getString(4));
            if (buildParams.isAllArtifact()) {
                artifact.setModule(rs.getString(5));
            }
            artifacts.add(artifact);
        }
        // update artifact repo path data
        if (!artifacts.isEmpty()) {
            rsArtCurr = getArtifactNodes(buildParams.getBuildName(), buildParams.getCurrBuildNum(),
                    artifactMap);
            if (buildParams.isAllArtifact()) {
                rsArtPrev = getArtifactNodes(buildParams.getBuildName(), buildParams.getComperedBuildNum(),
                        artifactMap);
            }
            for (ModuleArtifact artifact : artifacts) {
                ModuleArtifact moduleArtifact = artifactMap.get(artifact.getSha1());
                if (moduleArtifact != null) {
                    artifact.setRepoKey(moduleArtifact.getRepoKey());
                    artifact.setPath(moduleArtifact.getPath());
                }
            }
        }
    } catch (SQLException e) {
        log.error(e.toString());
    } finally {
        DbUtils.close(rsArtCurr);
        DbUtils.close(rsArtPrev);
        DbUtils.close(rs);
    }
    return artifacts;
}

From source file:fr.dyade.aaa.util.MySqlDBRepository.java

/**
 * Initializes the repository.//from www .java2  s  .  c  o  m
 * Opens the connection, evntually creates the database and tables.
 */
public void init(Transaction transaction, File dir) throws IOException {
    this.dir = dir;

    try {
        Class.forName(driver).newInstance();
        //       conn = DriverManager.getConnection(connurl + new File(dir, "JoramDB").getPath() + ";shutdown=true;server.no_system_exit=true", "sa", "");
        Properties props = new Properties();
        /*
        props.put("user", "user1");
        props.put("password", "user1");
         */
        props.put("user", user);
        props.put("password", pass);

        /*
        conn = DriverManager.getConnection(connurl + new File(dir, "JoramDB").getPath() + ";create=true", props);
         */
        // conn = DriverManager.getConnection(connurl, props); // MySQL (the database must exist and start seperately)
        conn = getConnection();
        conn.setAutoCommit(false);
    } catch (IllegalAccessException exc) {
        throw new IOException(exc.getMessage());
    } catch (ClassNotFoundException exc) {
        throw new IOException(exc.getMessage());
    } catch (InstantiationException exc) {
        throw new IOException(exc.getMessage());
    } catch (SQLException sqle) {
        throw new IOException(sqle.getMessage());
    }

    try {
        // Creating a statement lets us issue commands against the connection.
        Statement s = conn.createStatement();
        // We create the table.
        //         s.execute("create cached table JoramDB(name VARCHAR PRIMARY KEY, content VARBINARY(256))");
        /*
        s.execute("CREATE TABLE JoramDB (name VARCHAR(256), content LONG VARCHAR FOR BIT DATA, PRIMARY KEY(name))");
         */
        s.execute("CREATE TABLE JoramDB (name VARCHAR(256), content longblob, primary key(name))"); // MySQL
        s.close();
        conn.commit();
    } catch (SQLException sqle) {
        String exceptionString = sqle.toString();
        if (exceptionString.indexOf("CREATE command denied") == -1) {
            sqle.printStackTrace();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    try {
        insertStmt = conn.prepareStatement("INSERT INTO JoramDB VALUES (?, ?)");
        updateStmt = conn.prepareStatement("UPDATE JoramDB SET content=? WHERE name=?");
        deleteStmt = conn.prepareStatement("DELETE FROM JoramDB WHERE name=?");
    } catch (SQLException sqle) {
        sqle.printStackTrace();
        throw new IOException(sqle.getMessage());
    } catch (Exception e) {
        e.printStackTrace();
        // throw e;
    }
}