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 Connection getConnection(IConnection conn) throws SQLException {
    final String connURL = getConnectionURL(conn);
    LOGGER.info(MessageFormat.format(MySQLMessages.getString("capturer.mysql.connecting"), //$NON-NLS-1$
            connURL));//from w  w  w  . j  av  a 2  s .  c  o  m
    Connection connection = null;
    try {
        DriverManager.setLoginTimeout(15);
        connection = DriverManager.getConnection(connURL, conn.getLogin(), conn.getPassword());
    } catch (SQLException sqle) {
        LOGGER.error("Unable to connect to MySQL database: " + sqle.getMessage(), sqle);
        throw sqle;
    }
    LOGGER.info("MySQL connection established");
    return connection;
}

From source file:org.netxilia.server.rest.DataSourceResource.java

@GET
@Path("/{id}/test")
public String test(@PathParam("id") DataSourceConfigurationId id) throws StorageException, NotFoundException {
    try {// w w  w.  j a  va  2 s  .  c  o  m
        dataSourceConfigurationService.test(id);
        return "OK";
    } catch (SQLException e) {
        return e.getMessage();
    }
}

From source file:edu.lternet.pasta.dml.database.pooling.PostgresDatabaseConnectionPool.java

/**
 * Gets a database connection from the pool
 * //from w w w  . j  ava2  s. c o  m
 * @return checked out connection
 * @throws SQLException
 */
public Connection getConnection() throws SQLException, ConnectionNotAvailableException {
    Connection connection = null;

    try {
        connection = source.getConnection();
        connCount++;
    } catch (SQLException e) {
        System.err.println("SQLException: " + e.getMessage());
        throw (e);
    }

    return connection;
}

From source file:cz.zcu.kiv.eegdatabase.data.dao.SimpleLicenseDao.java

@Override
public byte[] getLicenseAttachmentContent(int licenseId) {
    String query = "from License l where l.licenseId = :id";
    License result = (License) this.getSession().createQuery(query).setInteger("id", licenseId).uniqueResult();
    try {//from w  ww.ja v  a2s  .c  om
        return result.getAttachmentContent() != null
                ? result.getAttachmentContent().getBytes(1, (int) result.getAttachmentContent().length())
                : new byte[0];
    } catch (SQLException e) {
        log.error(e.getMessage(), e);
        return new byte[0];
    }
}

From source file:org.owasp.webgoat.plugin.introduction.SqlInjectionLesson6a.java

protected AttackResult injectableQuery(String accountName) {
    try {/*from www .  j  a  va  2s .  co  m*/
        Connection connection = DatabaseUtilities.getConnection(getWebSession());
        String query = "SELECT * FROM user_data WHERE last_name = '" + accountName + "'";

        try {
            Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
                    ResultSet.CONCUR_READ_ONLY);
            ResultSet results = statement.executeQuery(query);

            if ((results != null) && (results.first())) {
                ResultSetMetaData resultsMetaData = results.getMetaData();
                StringBuffer output = new StringBuffer();

                output.append(SqlInjectionLesson5a.writeTable(results, resultsMetaData));
                results.last();

                // If they get back more than one user they succeeded
                if (results.getRow() >= 5) {
                    return trackProgress(success().feedback("sql-injection.6a.success")
                            .feedbackArgs(output.toString()).build());
                } else {
                    return trackProgress(failed().output(output.toString()).build());
                }

            } else {
                return trackProgress(failed().feedback("sql-injection.6a.no.results").build());

            }
        } catch (SQLException sqle) {
            return trackProgress(failed().output(sqle.getMessage()).build());
        }
    } catch (Exception e) {
        e.printStackTrace();
        return trackProgress(failed().output(this.getClass().getName() + " : " + e.getMessage()).build());
    }
}

From source file:com.manning.junitbook.ch14.ejbs.TestAdministratorEJB.java

/**
 * Test the {@link AdministratorBean#execute(String)} method by passing invalid query
 * //from  ww w . jav  a2  s.  co  m
 * @throws Exception
 */
public void testAdministratorBeanPassInvalidQueryShouldResultInException() throws Exception {
    try {
        //This query is invalid but it will pass our filter
        administrator.execute("SELECT ...");
    } catch (SQLException sqlex) {
        assertEquals(sqlex.getMessage(), "Unexpected token: . in statement [SELECT .]");
    }
}

From source file:com.nextep.designer.sqlgen.mssql.impl.MSSQLDatabaseConnector.java

@Override
public Connection getConnection(IConnection conn) throws SQLException {
    final String connURL = getConnectionURL(conn);
    LOGGER.info("Connecting to SQL Server database from URL [" + connURL + "]..."); //$NON-NLS-2$
    Connection connection = null;
    try {/*from ww  w. j  a v  a2 s  .  c o m*/
        connection = getDriver().connect(connURL, getConnectionInfo(conn));
    } catch (SQLException sqle) {
        LOGGER.error("Unable to connect to SQL Server database: " + sqle.getMessage(), sqle);
        throw sqle;
    }
    LOGGER.info("SQL Server connection established");
    return connection;
}

From source file:FlavorListServlet.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    PrintWriter out = response.getWriter();
    response.setContentType("text/html");

    // Get the bounds of the ranks to be listed
    // or use defaults

    int lowLimit = getLimit(request.getParameter("lowLimit"), 0);
    int highLimit = getLimit(request.getParameter("highLimit"), 100);

    Connection con = null;//from   w w w.j av  a  2s.c o m
    try {

        // Connect to the ice cream database

        Class.forName(JDBC_DRIVER);
        con = DriverManager.getConnection(URL);

        // Run a query to get the top flavors

        String sql = "SELECT  RANK, NAME" + "   FROM flavors" + "   WHERE RANK BETWEEN ? AND ?"
                + "   ORDER BY RANK";
        PreparedStatement pstmt = con.prepareStatement(sql);
        pstmt.setInt(1, lowLimit);
        pstmt.setInt(2, highLimit);
        ResultSet rs = pstmt.executeQuery();

        // Print as an ordered list

        out.println("<ol>");
        while (rs.next()) {
            int rank = rs.getInt(1);
            String name = rs.getString(2);
            out.println("   <li>" + name + "</li>");
        }
        out.println("</ol>");
    } catch (SQLException e) {
        throw new ServletException(e.getMessage());
    } catch (ClassNotFoundException e) {
        throw new ServletException(e.getMessage());
    }

    // Close the database

    finally {
        if (con != null) {
            try {
                con.close();
            } catch (SQLException ignore) {
            }
        }
    }
}

From source file:com.nextep.designer.sqlgen.postgre.impl.PostgreSqlDatabaseConnector.java

@Override
public Connection getConnection(IConnection conn) throws SQLException {
    final String connURL = getConnectionURL(conn);
    LOGGER.info("Connecting to PostgreSQL database from URL [" + connURL + "]..."); //$NON-NLS-2$
    Connection connection = null;
    try {//from   w  ww  . j av a2s . com
        connection = DriverManager.getConnection(connURL, conn.getLogin(), conn.getPassword());
    } catch (SQLException sqle) {
        LOGGER.error("Unable to connect to PostgreSQL database: " + sqle.getMessage(), sqle);
        throw sqle;
    }
    LOGGER.info("PostgreSQL connection established");
    return connection;
}

From source file:org.owasp.webgoat.plugin.introduction.SqlInjectionLesson5b.java

protected AttackResult injectableQuery(String accountName) {
    try {/* w w w  .  j  a va  2  s .c o m*/
        Connection connection = DatabaseUtilities.getConnection(getWebSession());
        String query = "SELECT * FROM user_data WHERE userid = " + accountName;

        try {
            Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
                    ResultSet.CONCUR_READ_ONLY);
            ResultSet results = statement.executeQuery(query);

            if ((results != null) && (results.first() == true)) {
                ResultSetMetaData resultsMetaData = results.getMetaData();
                StringBuffer output = new StringBuffer();

                output.append(SqlInjectionLesson5a.writeTable(results, resultsMetaData));
                results.last();

                // If they get back more than one user they succeeded
                if (results.getRow() >= 6) {
                    return trackProgress(success().feedback("sql-injection.5b.success")
                            .feedbackArgs(output.toString()).build());
                } else {
                    return trackProgress(failed().output(output.toString()).build());
                }

            } else {
                return trackProgress(failed().feedback("sql-injection.5b.no.results").build());

                //                    output.append(getLabelManager().get("NoResultsMatched"));
            }
        } catch (SQLException sqle) {

            return trackProgress(failed().output(sqle.getMessage()).build());
        }
    } catch (Exception e) {
        e.printStackTrace();
        return trackProgress(failed().output(this.getClass().getName() + " : " + e.getMessage()).build());
    }
}