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.l2jfree.gameserver.instancemanager.AuctionManager.java

private final void load() {
    Connection con = null;/*from   w  w w  .  jav a2s.  com*/
    try {
        PreparedStatement statement;
        ResultSet rs;
        con = L2DatabaseFactory.getInstance().getConnection(con);
        statement = con.prepareStatement("SELECT id FROM auction ORDER BY id");
        rs = statement.executeQuery();
        while (rs.next())
            _auctions.add(new Auction(rs.getInt("id")));
        statement.close();
        _log.info("AuctionManager: loaded " + getAuctions().size() + " auction(s)");
    } catch (SQLException e) {
        _log.fatal("Exception: AuctionManager.load(): " + e.getMessage(), e);
    } finally {
        L2DatabaseFactory.close(con);
    }
}

From source file:es.tid.cosmos.platform.injection.server.FrontendPassword.java

@Override
public boolean authenticate(String username, String password, ServerSession session) {
    LOG.debug(String.format("received %s as username, %d chars as password", username, password.length()));
    boolean ans = false;
    ResultSet resultSet = null;//from  www. j  a v a2 s .  c  om
    PreparedStatement preparedStatement = null;
    Connection connection = null;

    try {
        connection = this.connect(this.frontendDbUrl, this.dbName, this.dbUserName, this.dbPassword);
        String sql = "SELECT password FROM auth_user WHERE username = ?";
        preparedStatement = connection.prepareStatement(sql);
        preparedStatement.setString(1, username);
        resultSet = preparedStatement.executeQuery();
        String algorithm = "";
        String hash = "";
        String salt = "";

        while (resultSet.next()) {
            StringTokenizer algorithmSaltHash = new StringTokenizer(resultSet.getString(1), DJANGO_SEPARATOR);
            algorithm = algorithmSaltHash.nextToken();
            salt = algorithmSaltHash.nextToken();
            hash = algorithmSaltHash.nextToken();
        } // while

        if (algorithm.equals("sha1")) {
            ans = hash.equals(DigestUtils.shaHex(salt + password));
        } else if (algorithm.equals("md5")) {
            ans = hash.equals(DigestUtils.md5Hex(salt + password));
        } else {
            LOG.warn("Unknown algorithm found in DB: " + algorithm);
        } // if else if
    } catch (SQLException e) {
        LOG.error(e.getMessage(), e);
        return false;
    } finally {
        if (resultSet != null) {
            try {
                resultSet.close();
            } catch (SQLException e) {
                LOG.error("could not close a result set", e);
            } // try catch
        } // if

        if (preparedStatement != null) {
            try {
                preparedStatement.close();
            } catch (SQLException e) {
                LOG.error("could not close a database statement", e);
            } // try catch
        } // if

        if (connection != null) {
            try {
                connection.close();
            } catch (SQLException e) {
                LOG.error("could not close a database connection", e);
            } // try catch
        } // if
    } // try catch finally

    return ans;
}

From source file:net.certifi.audittablegen.PostgresqlDMR.java

public void printDataSourceStats() {
    try {/*from   w w  w.  ja va2s. c o  m*/
        if (dataSource.isWrapperFor(BasicDataSource.class)) {
            BasicDataSource bds = dataSource.unwrap(BasicDataSource.class);
            System.out.println("NumActive: " + bds.getNumActive());
            System.out.println("NumIdle: " + bds.getNumIdle());

        } else {
            System.out.println("DataSource Stats not available");
        }
    } catch (SQLException ex) {
        logger.error("Error getting DataSource stats:" + ex.getMessage());
    }

}

From source file:net.duckling.falcon.api.boostrap.BootstrapDao.java

private void execute(Connection conn, String sql) {
    Statement statement = null;/*from  ww w.j a  v a 2  s.  com*/
    try {
        statement = conn.createStatement();
        statement.execute(sql);
    } catch (SQLException e) {
        throw new WrongSQLException(e.getMessage());
    } finally {
        if (statement != null) {
            try {
                statement.close();
            } catch (SQLException e) {
                throw new WrongSQLException(e.getMessage());
            }
        }
    }
}

From source file:it.larusba.neo4j.jdbc.http.driver.Neo4jResponse.java

/**
 * Transform the error list to a string for display purpose.
 *
 * @return A String with all errors// ww  w.  jav  a2s  .  co  m
 */
public String displayErrors() {
    StringBuffer sb = new StringBuffer();
    if (hasErrors()) {
        sb.append("Some errors occurred : \n");
        for (SQLException error : errors) {
            sb.append("[").append(error.getSQLState()).append("]").append(":").append(error.getMessage())
                    .append("\n");
        }
    }
    return sb.toString();
}

From source file:eionet.cr.dao.virtuoso.VirtuosoSpoBinaryDAO.java

public boolean exists(String subjectUri) throws DAOException {

    if (StringUtils.isBlank(subjectUri)) {
        throw new IllegalArgumentException("Subject uri must not be blank");
    }/*w w  w.j  a  v  a2s . com*/

    Connection conn = null;
    try {
        conn = getSQLConnection();
        Object o = SQLUtil.executeSingleReturnValueQuery(SQL_EXISTS,
                Collections.singletonList(Long.valueOf(Hashes.spoHash(subjectUri))), conn);
        return o != null && Integer.parseInt(o.toString()) > 0;
    } catch (SQLException e) {
        throw new DAOException(e.getMessage(), e);
    } finally {
        SQLUtil.close(conn);
    }
}

From source file:gov.nih.nci.cacisweb.dao.virtuoso.VirtuosoCommonUtilityDAO.java

/**
 * Gets the next sequence by suffixing '_SEQ' to the table name
 * // w ww  .j  av  a2 s.co m
 * @param tableName
 * @return
 * @throws DAOException
 */
public long getNextSequenceBySequenceName(String sequenceName) throws DAOException {
    log.debug("getNextSequenceByTableName(String sequenceName) - start");
    long sequenceNum = 0;
    StringBuffer sequenceSQL = new StringBuffer();
    sequenceSQL.append("SELECT " + sequenceName + ".nextval from dual");
    try {
        pstmt = new LoggableStatement(cacisConnection, sequenceSQL.toString());
        log.info("SQL getNextSequenceByTableName(String sequenceName) : " + pstmt.toString());
        ResultSet rs = pstmt.executeQuery();
        if (rs.next()) {
            sequenceNum = rs.getLong("NEXTVAL");
        }
    } catch (SQLException sqle) {
        log.error(sqle.getMessage());
        sqle.printStackTrace();
        throw new DAOException(sqle.getMessage());
    }
    return sequenceNum;
}

From source file:org.dspace.versioning.VersionServiceImpl.java

@Override
public Version createVersion(Context c, VersionHistory vh, Item item, String summary, Date date,
        int versionNumber) {
    try {/*w w  w  .ja  va2  s .  c o m*/
        Version version = versionDAO.create(c, new Version());

        version.setVersionNumber(versionNumber);
        version.setVersionDate(date);
        version.setePerson(item.getSubmitter());
        version.setItem(item);
        version.setSummary(summary);
        version.setVersionHistory(vh);
        versionDAO.save(c, version);
        versionHistoryService.add(vh, version);
        return version;
    } catch (SQLException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}

From source file:dao.CarryonBlobUpdate.java

/**
* This method is used to add blobstreams for a user. <code>Userpage</code>
* @param blob - the blob stream//from w w  w  .j  ava2s . c o m
* @param category - the blob type (1 - photos, 2-music, 3-video 4 - documents, 5 - archives)
* @param mimeType - the mime type (image/jpeg, application/octet-stream)
* @param btitle - the title for this blob
* @param loginId - the loginId
* @param bsize - the size of the blob
* @param zoom - the zoom for the blob (used for displaying for image/jpeg)
* @throws Dao Exception - when an error or exception occurs while inserting this blob in DB.
*
 **/
public void run(Connection conn, byte[] blob, int category, String mimeType, String btitle, String loginId,
        long bsize, int zoom, String caption) throws BaseDaoException {

    byte[] capBytes = { ' ' };
    if (!RegexStrUtil.isNull(caption)) {
        capBytes = caption.getBytes();
    }

    //long dt = System.currentTimeMillis();
    // Connection conn = null;
    String stmt = "insert into carryon values(?, ?, ?, ?, ?, CURRENT_TIMESTAMP(), ?, ?, ?, ?, ?)";
    PreparedStatement s = null;
    try {
        //    conn = dataSource.getConnection();
        s = conn.prepareStatement(stmt);
        s.setLong(1, 0); // entryid
        s.setLong(2, new Long(loginId)); // loginid
        s.setInt(3, new Integer(category)); // category
        s.setString(4, mimeType); // mimetype
        s.setString(5, btitle); // btitle
        // s.setDate(6, new Date(dt));
        // s.setDate(6, CURRENT_TIMESTAMP());
        s.setBytes(6, blob);
        s.setLong(7, bsize);
        s.setInt(8, new Integer(zoom));
        s.setInt(9, 0); // hits
        s.setBytes(10, capBytes); // caption
        s.executeUpdate();
    } catch (SQLException e) {
        logger.error("Error adding a blob.", e);
        throw new BaseDaoException("Error adding a blob " + e.getMessage(), e);
    }
}

From source file:TransactionConnectionServlet.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {

    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    out.println("<html>");
    out.println("<head>");
    out.println("<title>A Per Transaction Connection</title>");
    out.println("</head>");
    out.println("<body>");

    Connection connection = null;
    try {/*from ww  w  .  j a v  a 2s  .c o m*/
        // establish a connection
        connection = DriverManager.getConnection("jdbc:oracle:thin:@dssw2k01:1521:orcl", "scott", "tiger");
    } catch (SQLException e) {
        throw new UnavailableException("TransactionConnection.init() SQLException: " + e.getMessage());
    }

    Statement statement = null;
    ResultSet resultSet = null;
    String userName = null;
    try {
        // test the connection
        statement = connection.createStatement();
        resultSet = statement.executeQuery("select initcap(user) from sys.dual");
        if (resultSet.next())
            userName = resultSet.getString(1);
    } catch (SQLException e) {
        out.println("TransactionConnection.doGet() SQLException: " + e.getMessage() + "<p>");
    } finally {
        if (resultSet != null)
            try {
                resultSet.close();
            } catch (SQLException ignore) {
            }
        if (statement != null)
            try {
                statement.close();
            } catch (SQLException ignore) {
            }
    }

    if (connection != null) {
        // close the connection
        try {
            connection.close();
        } catch (SQLException ignore) {
        }
    }

    out.println("Hello " + userName + "!<p>");
    out.println("You're using a per transaction connection!<p>");
    out.println("</body>");
    out.println("</html>");
}