Example usage for java.sql SQLException getClass

List of usage examples for java.sql SQLException getClass

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:com.clustercontrol.sql.util.AccessDB.java

/**
 * DB???//  ww  w.j a  va 2 s.c o m
 *
 * @throws SQLException
 * @throws ClassNotFoundException
 */
private void initial() throws SQLException, ClassNotFoundException {
    //JDBC??
    try {
        Class.forName(m_jdbcDriver);
    } catch (ClassNotFoundException e) {
        m_log.info("initial() : " + e.getClass().getSimpleName() + ", " + e.getMessage());
        throw e;
    }

    Properties prop = jdbcProps.getProperties();
    prop.put("user", m_user);
    prop.put("password", m_password);

    try {
        if (jdbcProps.isLoginTimeoutEnable()) {
            DriverManager.setLoginTimeout(jdbcProps.getLoginTimeout());
            m_log.debug(
                    "enabled loginTimeout (" + jdbcProps.getLoginTimeout() + " [sec]) for \"" + m_url + "\".");
        } else {
            m_log.debug("disabled loginTimeout for \"" + m_url + "\".");
        }
        m_connection = DriverManager.getConnection(m_url, prop);

        //SQL????Statement?
        m_statement = m_connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
                ResultSet.CONCUR_READ_ONLY);

    } catch (SQLException e) {
        m_log.info("initial() database access failure : url = " + m_url + ", : " + e.getClass().getSimpleName()
                + ", " + e.getMessage());
        try {
            if (m_statement != null)
                m_statement.close();
        } catch (SQLException se) {
            m_log.info("initial() database closing failure : url = " + m_url + ", "
                    + se.getClass().getSimpleName() + ", " + se.getMessage());
        }
        try {
            if (m_connection != null)
                m_connection.close();
        } catch (SQLException se) {
            m_log.info("initial() database closing failure : url = " + m_url + ", "
                    + se.getClass().getSimpleName() + ", " + se.getMessage());
        }
        throw e;
    }
}

From source file:biopolis.headless.BiopolisManager.java

public WSResult<BiopolisResult<T>> getIT(long pkgid) {
    try {// w w  w  . j a  v  a 2  s .  com
        Long[] ids = { pkgid };
        return new WSResult<BiopolisResult<T>>(this.get(ids));
    } catch (SQLException ex) {
        return new WSResult<BiopolisResult<T>>(ex.getClass().getName(), ex.getMessage());
    } catch (BiopolisGeneralException ex) {
        return new WSResult<BiopolisResult<T>>(ex.getClass().getName(), ex.getMessage());
    }
}

From source file:biopolis.headless.BiopolisManager.java

public WSResult<BiopolisResult<T>> getActive(long userid) {
    try {//www .  jav  a  2 s .c  om
        BiopolisSegmentation seg = this.getFromUser(userid);
        BiopolisSegmentQuery seg_q = new BiopolisSegmentQuery();
        seg_q.nodetype = seg.nodetype;
        seg_q.biopolisid = seg.biopolisid;
        seg_q.from = 0;
        List<Long> ll = this.bgr.seg_mgmnt.search(seg_q);
        Long[] ids = ll.toArray(new Long[0]);
        return new WSResult<BiopolisResult<T>>(this.get(ids));
    } catch (SQLException ex) {
        return new WSResult<BiopolisResult<T>>(ex.getClass().getName(), ex.getMessage());
    } catch (BiopolisGeneralException ex) {
        return new WSResult<BiopolisResult<T>>(ex.getClass().getName(), ex.getMessage());
    }
}

From source file:org.fornax.cartridges.sculptor.framework.errorhandling.ErrorHandlingAdvice.java

protected void handleDatabaseAccessException(Object target, Exception e) {
    Logger log = LoggerFactory.getLogger(target.getClass());

    // often the wrapped SQLException contains the interesting piece of
    // information
    StringBuilder message = new StringBuilder();
    message.append(e.getClass().getName()).append(": ");
    message.append(excMessage(e));/*from w  ww  .  ja v  a2s.co  m*/
    SQLException sqlExc = ExceptionHelper.unwrapSQLException(e);
    Throwable realException = sqlExc;
    if (sqlExc != null) {
        message.append(", Caused by: ");
        message.append(sqlExc.getClass().getName()).append(": ");
        message.append(excMessage(sqlExc));
        if (sqlExc.getNextException() != null) {
            message.append(", Next exception: ");
            message.append(sqlExc.getNextException().getClass().getName()).append(": ");
            message.append(excMessage(sqlExc.getNextException()));
            realException = sqlExc.getNextException();
        }
    }

    if (isJmsContext() && !isJmsRedelivered()) {
        LogMessage logMessage = new LogMessage(mapLogCode(DatabaseAccessException.ERROR_CODE),
                message.toString());
        log.info("{}", logMessage);
    } else {
        LogMessage logMmessage = new LogMessage(mapLogCode(DatabaseAccessException.ERROR_CODE),
                message.toString());
        log.error(logMmessage.toString(), e);
    }

    DatabaseAccessException newException = new DatabaseAccessException(message.toString(), realException);
    newException.setLogged(true);
    throw newException;
}

From source file:org.seasar.dbflute.exception.handler.SQLExceptionHandler.java

protected void setupSQLExceptionElement(ExceptionMessageBuilder br, SQLException e) {
    br.addItem("SQLException");
    br.addElement(e.getClass().getName());
    br.addElement(extractMessage(e));//from   w ww.  j  a  v  a2 s . c o m
    final SQLException nextEx = e.getNextException();
    if (nextEx != null) {
        br.addItem("NextException");
        br.addElement(nextEx.getClass().getName());
        br.addElement(extractMessage(nextEx));
        final SQLException nextNextEx = nextEx.getNextException();
        if (nextNextEx != null) {
            br.addItem("NextNextException");
            br.addElement(nextNextEx.getClass().getName());
            br.addElement(extractMessage(nextNextEx));
        }
    }
}

From source file:edu.fullerton.ldvservlet.Upload.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
 *
 * @param request servlet request/*from w  w  w. j  a  v  a 2s .c  om*/
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    long startTime = System.currentTimeMillis();

    if (!ServletFileUpload.isMultipartContent(request)) {
        throw new ServletException("This action requires a multipart form with a file attached.");
    }
    ServletSupport servletSupport;

    servletSupport = new ServletSupport();
    servletSupport.init(request, viewerConfig, false);

    // Create a factory for disk-based file items
    DiskFileItemFactory factory = new DiskFileItemFactory();

    // Configure a repository (to ensure a secure temp location is used)
    ServletContext servletContext = this.getServletConfig().getServletContext();
    File repository = (File) servletContext.getAttribute("javax.servlet.context.tempdir");
    factory.setRepository(repository);

    // Create a new file upload handler
    ServletFileUpload upload = new ServletFileUpload(factory);

    ImageTable imageTable;
    String viewServletPath = request.getContextPath() + "/view";

    try {
        imageTable = new ImageTable(servletSupport.getDb());
    } catch (SQLException ex) {
        String ermsg = "Image upload: can't access the Image table: " + ex.getClass().getSimpleName() + " "
                + ex.getLocalizedMessage();
        throw new ServletException(ermsg);
    }
    try {
        HashMap<String, String> params = new HashMap<>();
        ArrayList<Integer> uploadedIds = new ArrayList<>();

        Page vpage = servletSupport.getVpage();
        vpage.setTitle("Image upload");
        try {
            servletSupport.addStandardHeader(version);
            servletSupport.addNavBar();
        } catch (WebUtilException ex) {
            throw new ServerException("Adding nav bar after upload", ex);
        }

        // Parse the request
        List<FileItem> items = upload.parseRequest(request);
        int cnt = items.size();
        for (FileItem item : items) {
            if (item.isFormField()) {
                String name = item.getFieldName();
                String value = item.getString();
                if (!value.isEmpty()) {
                    params.put(name, value);
                }
            }
        }
        for (FileItem item : items) {
            if (!item.isFormField()) {
                int imgId = addFile(item, params, vpage, servletSupport.getVuser().getCn(), imageTable);
                if (imgId != 0) {
                    uploadedIds.add(imgId);
                }
            }
        }
        if (!uploadedIds.isEmpty()) {
            showImages(vpage, uploadedIds, imageTable, viewServletPath);
        }
        servletSupport.showPage(response);
    } catch (FileUploadException ex) {
        Logger.getLogger(Upload.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.oracle.tutorial.jdbc.CoffeesFrame.java

private void displaySQLExceptionDialog(SQLException e) {

    // Display the SQLException in a dialog box
    JOptionPane.showMessageDialog(CoffeesFrame.this,
            new String[] { e.getClass().getName() + ": ", e.getMessage() });
}

From source file:chanupdater.ChanUpdater.java

private void cleanUp() throws WebUtilException, MalformedURLException, IOException {
    try {//from   w  ww. java  2s .  c  o m
        chnTbl.optimize();
        PageItemCache pic = new PageItemCache(db);
        String cmd = "DELETE FROM " + pic.getName() + " WHERE name='ChannelStats'";
        db.execute(cmd);

        //            // get a kerberos ticket
        //            String home = System.getenv("HOME");
        //            String keytab = home + "/secure/joseph.areeda.keytab";
        //            String user = "joseph.areeda@LIGO.ORG";
        //            ExternalProgramManager.getTGT(keytab, user);
        //
        //            String chstatUrl = "http://localhost/viewer/?act=ChannelStats";
        //            URL url = new URL(chstatUrl);
        //            InputStream is = url.openConnection().getInputStream();
        //
        //            try (BufferedReader reader = new BufferedReader(new InputStreamReader(is)))
        //            {
        //                String line = null;               
        //                while ((line = reader.readLine()) != null)
        //                {
        //                    
        //                }
        //            }
    } catch (SQLException ex) {
        String ermsg = "Error optimizing table: " + ex.getClass().getSimpleName();
        ermsg += " - " + ex.getLocalizedMessage();
        throw new WebUtilException(ermsg);
    }
}

From source file:databaseadapter.GenerateMojo.java

protected Collection<Table> collectTables() throws MojoExecutionException {
    ResultSet rstables = null;/* ww w.  j  a va2s . c o  m*/
    try {
        List<Table> tables = new LinkedList<Table>();
        DatabaseMetaData metaData = connection.getMetaData();
        rstables = metaData.getTables(null, schemaPattern, "%", new String[] { "TABLE" });
        while (rstables.next()) {
            String schema = rstables.getString("TABLE_SCHEM");
            String table = rstables.getString("TABLE_NAME");
            String type = rstables.getString("TABLE_TYPE");
            String remarks = rstables.getString("REMARKS");
            getLog().debug("... found table " + schema + "." + table + " (" + type + ")...");
            if (isToInclude(table)) {
                if (!isToExclude(table)) {
                    getLog().debug("... processing...");
                    Table t = new Table(table, remarks);
                    tables.add(t);

                } else {
                    getLog().debug("... skipping due to 'excludes' pattern(s)");
                }
            } else {
                getLog().debug("... skipping due to 'includes' pattern(s)");
            }
        }

        getLog().info("... found to process " + tables.size() + " tables: " + tables);
        return tables;
    } catch (SQLException e) {
        throw new MojoExecutionException("Unable to generate database adapter due to a '"
                + e.getClass().getName() + "' with message '" + e.getMessage() + "'", e);
    } finally {
        if (rstables != null) {
            try {
                rstables.close();
            } catch (SQLException ignore) {
            }
        }
    }
}

From source file:databaseadapter.GenerateMojo.java

protected Map<Table, List<Column>> collectColumns(Collection<Table> tables) throws MojoExecutionException {
    ResultSet rscolumns = null;/*  ww  w  . j av a  2  s. c o  m*/
    try {
        Map<Table, List<Column>> map = new LinkedHashMap<Table, List<Column>>();
        DatabaseMetaData metaData = connection.getMetaData();
        rscolumns = metaData.getColumns(null, schemaPattern, "%", "%");
        while (rscolumns.next()) {
            String tableName = rscolumns.getString("TABLE_NAME");
            Table table = find(tables, tableName);
            if (table == null)
                continue;

            List<Column> columns = map.get(table);
            if (columns == null) {
                columns = new LinkedList<Column>();
                map.put(table, columns);
            }

            String columnName = rscolumns.getString("COLUMN_NAME");
            int dataType = rscolumns.getInt("DATA_TYPE");
            int columnSize = rscolumns.getInt("COLUMN_SIZE");
            int decimalDigits = rscolumns.getInt("DECIMAL_DIGITS");
            int nullable = rscolumns.getInt("NULLABLE");
            String remarks = rscolumns.getString("REMARKS");

            Column column = new Column(columnName, dataType, columnSize, decimalDigits,
                    nullable == DatabaseMetaData.columnNullable, remarks);
            columns.add(column);
        }

        return map;
    } catch (SQLException e) {
        throw new MojoExecutionException("Unable to generate database adapter due to a '"
                + e.getClass().getName() + "' with message '" + e.getMessage() + "'", e);
    } finally {
        if (rscolumns != null) {
            try {
                rscolumns.close();
            } catch (SQLException ignore) {
            }
        }
    }
}