Example usage for java.sql SQLException printStackTrace

List of usage examples for java.sql SQLException printStackTrace

Introduction

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

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:br.gov.jfrj.siga.gc.gsa.GcInformacaoAdaptor.java

protected void pushDocIds(DocIdPusher pusher, Date date) throws InterruptedException {
    Connection conn = null;//from  ww w .java  2  s  .c o m
    Statement stmt = null;
    String query = "select id_informacao from sigagc.gc_informacao where numero is not null and his_dt_fim is null";
    try {
        BufferingPusher outstream = new BufferingPusher(pusher);

        conn = getConnection();
        stmt = conn.createStatement();
        ResultSet rs = stmt.executeQuery(query);
        while (rs.next()) {
            DocId id = new DocId("" + rs.getLong("ID_INFORMACAO"));
            outstream.add(id);
        }
        outstream.forcePush();
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    } finally {
        if (stmt != null) {
            try {
                stmt.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
}

From source file:com.abixen.platform.module.chart.service.impl.AbstractDatabaseService.java

public List<String> getColumns(Connection connection, String tableName) {

    List<String> columns = new ArrayList<>();

    try {//  ww w  .jav a  2 s .c  o m
        Statement stmt = connection.createStatement();
        ResultSet rs = stmt.executeQuery("SELECT * FROM " + tableName);
        ResultSetMetaData rsmd = rs.getMetaData();

        int columnCount = rsmd.getColumnCount();

        IntStream.range(1, columnCount + 1).forEach(i -> {
            try {
                columns.add(rsmd.getColumnName(i));
            } catch (SQLException e) {
                e.printStackTrace();
            }
        });

    } catch (SQLException e) {
        e.printStackTrace();
    }

    return columns;
}

From source file:org.fornax.cartridges.sculptor.framework.util.db.DatabaseExport.java

public List<String> getTables(Connection connection) {
    List<String> tables = new ArrayList<String>();
    PreparedStatement pstmt = null;
    try {//  w w  w .jav a 2 s .  com
        pstmt = connection.prepareStatement(environmentStrategy.getSqlAllTables());

        ResultSet rset = pstmt.executeQuery();
        while (rset.next()) {
            tables.add(rset.getString("table_name"));
        }
    } catch (SQLException e) {
        System.out.println("SQLException: " + e.getMessage());
        e.printStackTrace();
    } finally {
        if (pstmt != null) {
            try {
                pstmt.close();
            } catch (SQLException ignore) {
            }
        }
    }

    return tables;

}

From source file:br.gov.jfrj.siga.gc.gsa.GcInformacaoAdaptor.java

public Date getSysdate() {
    Date currentDate = null;//from ww  w . jav  a 2 s .com
    Connection conn = null;
    Statement stmt = null;
    String query = "SELECT SYSDATE FROM DUAL";
    try {
        conn = getConnection();
        stmt = conn.createStatement();

        // Execute a SELECT query on Oracle Dummy DUAL Table. Useful for
        // retrieving system values
        // Enables us to retrieve values as if querying from a table
        ResultSet rs = stmt.executeQuery(query);
        if (rs.next()) {
            currentDate = rs.getDate(1); // get first column returned
            System.out.println("Current Date from Oracle is : " + currentDate);
        }
        rs.close();
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    } finally {
        if (stmt != null) {
            try {
                stmt.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
    return currentDate;
}

From source file:mendeley2kindle.Mendeley2Kindle.java

public void syncCollections(Collection<MCollection> collections, boolean syncAllDocuments,
        boolean removeOrphanedFile, boolean exportHighlights) {
    Collection<KFile> globalRemoved = new ArrayList<KFile>();
    for (SyncStateListener l : listeners)
        l.begin(collections.size());//from w  ww  .ja  va 2 s.  c  o  m
    for (MCollection col : collections) {
        for (SyncStateListener l : listeners)
            l.beginCollection(col);
        try {
            Collection<KFile> removed = new ArrayList<KFile>();
            Collection<MFile> added = new ArrayList<MFile>();
            Collection<MFile> updated = new ArrayList<MFile>();

            if (!kindle.hasKCollection(col.getName()))
                kindle.createKCollection(col.getName());
            Collection<KFile> kFiles = kindle.listFiles(col.getName());

            Collection<MFile> mFiles = null;

            if (col instanceof MFolder) {
                mFiles = mendeley.findFilesByCollection(((MFolder) col).getId());
            } else if (col instanceof MCondCollection) {
                mFiles = mendeley.findFilesByCondition(((MCondCollection) col).getCondition());

            } else {
                assert false : col;
            }
            Collection<String> msFiles = new ArrayList<String>();

            // Find updated/added/removed documents
            for (MFile mf : mFiles) {
                String url = mf.getLocalUrl();
                File f = new File(new URI(url));
                String name = f.getName();
                if (kFiles.contains(name)) {
                    updated.add(mf);
                } else {
                    added.add(mf);
                }
                msFiles.add(name);
            }
            for (KFile kFile : kFiles) {
                if (!msFiles.contains(kFile)) {
                    removed.add(kFile);
                    globalRemoved.add(kFile);
                }
            }

            // do action
            for (SyncStateListener l : listeners)
                l.beginAddFiles(added.size());
            for (MFile mf : added) {
                for (SyncStateListener l : listeners)
                    l.beginAddFile(mf.getName());
                kindle.saveFile(mf, exportHighlights);
                kindle.addFileToCollection(col.getName(), mf);
                for (SyncStateListener l : listeners)
                    l.endAddFile();
            }
            for (SyncStateListener l : listeners)
                l.endAddFiles();

            for (SyncStateListener l : listeners)
                l.beginUpdateFiles(updated.size());
            for (MFile mf : updated) {
                for (SyncStateListener l : listeners)
                    l.beginUpdateFile(mf.getName());
                kindle.saveFile(mf, exportHighlights);
            }
            for (SyncStateListener l : listeners)
                l.endUpdateFiles(updated.size());

            for (SyncStateListener l : listeners)
                l.beginRemoveFiles(removed.size());
            for (KFile kFile : removed) {
                for (SyncStateListener l : listeners)
                    l.beginRemoveFile(kFile.getName());
                kindle.removeFile(col.getName(), kFile);
            }
            for (SyncStateListener l : listeners)
                l.endRemoveFiles(removed.size());

        } catch (SQLException e) {
            e.printStackTrace();
        } catch (URISyntaxException e) {
            e.printStackTrace();
            assert false;
        } catch (JSONException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        for (SyncStateListener l : listeners)
            l.endCollection();
    }

    // remove from kindle if the file is removed from mendeley db
    for (KFile kFile : globalRemoved) {
        MFile mf;
        try {
            mf = mendeley.findFileByHash(kFile.getHash());
            if (mf != null && syncAllDocuments)
                continue;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        Collection<String> kCols = kindle.findKCollectionsByFile(kFile);
        if (kCols.size() == 0 && removeOrphanedFile)
            kindle.removeFile(kFile);
    }
    try {
        kindle.commit();
    } catch (IOException e) {
        e.printStackTrace();
    }
    for (SyncStateListener l : listeners)
        l.end();
}

From source file:com.cloudera.sqoop.TestMerge.java

@Override
public void setUp() {
    super.setUp();
    manager = getManager();//from  www .j  a  va  2  s . co  m
    try {
        conn = manager.getConnection();
    } catch (SQLException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
}

From source file:com.cloudera.sqoop.manager.DirectMySQLExportTest.java

@Before
public void setUp() {
    super.setUp();

    SqoopOptions options = new SqoopOptions(MySQLTestUtils.CONNECT_STRING, getTableName());
    options.setUsername(MySQLTestUtils.getCurrentUser());
    this.manager = new DirectMySQLManager(options);

    try {// w  ww . j  ava 2s.c o m
        this.conn = manager.getConnection();
        this.conn.setAutoCommit(false);
    } catch (SQLException sqlE) {
        LOG.error("Encountered SQL Exception: " + sqlE);
        sqlE.printStackTrace();
        fail("SQLException when running test setUp(): " + sqlE);
    }
}

From source file:de.tudarmstadt.ukp.lmf.transform.sensealignments.FramenetWordnetAlignment.java

/**
 * Collect UBY SenseIds for the aligned senses based on synsetId and lemma
 * for WordNet and based on lexical unit id for FrameNet
 *
 * @throws IllegalArgumentException/*from www  .j a v a2 s . c  o m*/
 */
@Override
public void getAlignment() throws IllegalArgumentException {
    List<String[]> data = null;
    data = readAlignmentFile();
    if (ubySource == null) {
        logger.warn("uby source is empty");
    }
    int counter = 0; // input sense pairs
    int found = 0; // output sense pairs
    // temp table for FN
    String declareFieldsFN = "senseId varchar(255) NOT NULL, externalReference varchar(255)";
    String sqlInsertDataFN = "SELECT S.senseId, " + " M.externalReference  "
            + " FROM Sense S JOIN MonolingualExternalRef M" + " ON (S.senseId=M.senseId)"
            + "where substring(S.senseId,1,2)=\"FN\"";
    String declareFieldsWN = "senseId varchar(255) NOT NULL, " + "synsetId varchar(255) NOT NULL, "
            + "writtenForm varchar(255) NOT NULL, " + "lexicalEntryId varchar(255) NOT NULL, "
            + "externalReference varchar(255)";
    // temp table for WN
    String sqlInsertDataWN = "SELECT Sense.senseId, Sense.synsetId,"
            + "FormRepresentation_Lemma.writtenForm,LexicalEntry.lexicalEntryId, "
            + "MonolingualExternalRef.externalReference "
            + "FROM Sense JOIN (MonolingualExternalRef,LexicalEntry,FormRepresentation_Lemma) "
            + "ON (Sense.synsetId=MonolingualExternalRef.synsetId "
            + "AND Sense.lexicalEntryId=LexicalEntry.lexicalEntryId "
            + "AND FormRepresentation_Lemma.lemmaId=LexicalEntry.lemmaId) "
            + "WHERE MonolingualExternalRef.externalSystem=\"WordNet_3.0_eng_synsetOffset\"";
    try {
        saUtils.createTempTable(declareFieldsWN, sqlInsertDataWN, 0);
        saUtils.createTempTable(declareFieldsFN, sqlInsertDataFN, 1);

    } catch (SQLException e1) {
        e1.printStackTrace();
    }
    // iterate over alignment entries
    for (String[] d : data) {
        counter++;
        // show progress:
        if ((counter % 1000) == 0) {
            logger.info("# processed alignments: " + counter);
        }

        List<String> wnSenses;
        List<Sense> fnSenses;
        try {
            // get FrameNet sense by ExternalReference (lexical unit Id)
            fnSenses = saUtils.getSensesByExternalRefID(d[0], 1, false);
            // get WordNet sense by Synset Offset and Lemma
            wnSenses = saUtils.getSensesByWNSynsetOffsetAndLemma(d[1], d[2].replace("_", " "), 0);
            if (fnSenses.size() == 1) { // exactly one fn sense
                Sense fns = fnSenses.get(0);
                if (wnSenses.size() == 1) { // exactly one wn sense
                    // add the data
                    addSourceSense(fns);
                    Sense wns = ubySource.getSenseById(wnSenses.get(0));
                    addDestSense(wns);
                    found++;
                } else if (wnSenses.size() == 0) { // no WN sense
                    logger.warn("WN sense not found: " + d[1] + " " + d[2].replace("_", " "));
                } else { // more than one WN sense
                    logger.info("More than one WN sense for this key: " + d[1] + " " + d[2].replace("_", " "));
                    for (String sid : wnSenses) {
                        Sense wns = ubySource.getSenseById(sid);
                        addSourceSense(fns);
                        addDestSense(wns);
                    }
                }
            } else if (fnSenses.size() == 0) {
                logger.warn("No FN sense for this key: " + d[0]);
            } else {
                logger.warn("More than one FN sense for this key: " + d[0]);
            }
        } catch (SQLException e1) {
            e1.printStackTrace();
        }
    }
    logger.info("Alignments in: " + counter + "Alignments out: " + found);
}

From source file:i5.las2peer.services.todolist.Todolist.java

/**
 * /*from w ww  . j  a  v a  2 s  .  c o m*/
 * deleteData
 * 
 * 
 * @return HttpResponse
 * 
 */
@DELETE
@Path("/data/{id}")
@Produces(MediaType.TEXT_PLAIN)
@Consumes(MediaType.TEXT_PLAIN)
@ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_OK, message = "responseDeleteData") })
@ApiOperation(value = "deleteData", notes = "")
public HttpResponse deleteData(@PathParam("id") Integer id) {
    Connection conn = null;
    try {

        conn = dbm.getConnection();
        PreparedStatement stmt = conn.prepareStatement("DELETE FROM gamificationCAE.todolist WHERE id = ?");
        stmt.setInt(1, id);
        stmt.executeUpdate();
        stmt = conn.prepareStatement("ALTER TABLE todolist AUTO_INCREMENT = 1;");
        stmt.executeUpdate();
        return new HttpResponse("data number " + id + " is deleted!", HttpURLConnection.HTTP_OK);

    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();

        return new HttpResponse("Database connection error", HttpURLConnection.HTTP_INTERNAL_ERROR);
    } finally {
        try {
            conn.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}

From source file:edu.lternet.pasta.dml.database.SimpleDatabaseLoader.java

/**
 * Determines whether the data table //w  ww.ja  v  a  2  s.c  o m
 * already exists in the database and is loaded with data. This method is
 * mandated by the DataStorageInterface.
 * 
 * First, check that the data table exists. Second, check that the row count
 * is greater than zero. (We want to make sure that the table has not only
 * been created, but has also been loaded with data.)
 * 
 * @param identifier
 *            the identifier for the data table
 * @return true if the data table has been loaded into the database, else
 *         false
 */
public boolean doesDataExist(String identifier) {
    boolean doesExist = false;

    try {
        String tableName = tableMonitor.identifierToTableName(identifier);
        doesExist = tableMonitor.isTableInDB(tableName);

        if (doesExist) {
            int rowCount = tableMonitor.countRows(tableName);
            doesExist = (rowCount > 0);
        }
    } catch (SQLException e) {
        log.error(e.getMessage());
        e.printStackTrace();
    }

    return doesExist;
}