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:edu.ku.brc.specify.dbsupport.cleanuptools.LocalityCleanup.java

public static void fixOld() {
    String connectStr = "jdbc:mysql://localhost/";

    String dbName = "kevin";

    DBConnection dbc = new DBConnection("root", "root", connectStr + dbName, "com.mysql.jdbc.Driver",
            "org.hibernate.dialect.MySQLDialect", dbName);
    Connection conn = dbc.createConnection();
    BasicSQLUtils.setDBConnection(conn);

    try {/*from  w w w  .  java  2 s . c  o m*/
        String sql = "SELECT LocalityName, cnt FROM (SELECT LocalityName, COUNT(LocalityName) as cnt FROM locality GROUP BY LocalityName) T1 WHERE cnt > 1 ORDER BY cnt desc ";

        Statement stmt = conn.createStatement();
        Statement stmt2 = conn.createStatement();
        PreparedStatement pStmt = conn
                .prepareStatement("UPDATE collectingevent SET LocalityID=? WHERE CollectingEventID = ?");

        int fixedCnt = 0;
        ResultSet rs = stmt.executeQuery(sql);
        while (rs.next()) {
            String locName = rs.getString(1);
            int cnt = rs.getInt(2);

            sql = String.format(
                    "SELECT LocalityID FROM locality WHERE LocalityName = '%s' ORDER BY LocalityID ASC",
                    locName);
            System.out.println(
                    "------------------------------------" + locName + "-----------------------------------");

            int c = 0;
            Integer firstID = null;

            ResultSet rs2 = stmt2.executeQuery(sql);
            while (rs2.next()) {
                int id = rs2.getInt(1);
                if (c == 0) {
                    firstID = id;
                    c = 1;
                    continue;
                }

                System.out.println("Fixing LocalityID: " + id);
                sql = String.format("SELECT CollectingEventId FROM collectingevent WHERE LocalityID = %d", id);
                Vector<Integer> ids = BasicSQLUtils.queryForInts(conn, sql);
                for (Integer ceId : ids) {
                    pStmt.setInt(1, firstID);
                    pStmt.setInt(2, ceId);
                    if (pStmt.executeUpdate() != 1) {
                        System.out.println("Error updating CE Id: " + ceId);
                    } else {
                        System.out
                                .println("Fixed CollectingEventID: " + ceId + "  with LocalityID: " + firstID);
                        fixedCnt++;
                    }
                }
                c++;
            }
            rs2.close();

            if (c != cnt) {
                System.out.println("Error updating all Localities for " + locName);
            }
        }
        rs.close();

        stmt.close();
        stmt2.close();
        pStmt.close();

        System.out.println("Fixed CE Ids: " + fixedCnt);

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

From source file:HSqlPrimerDesign.java

public static void checker(Connection connection, int bps) throws ClassNotFoundException, SQLException,
        InstantiationException, IllegalAccessException, IOException {
    String base = new File("").getAbsolutePath();
    Connection db = connection;/* w  w w.  j  a  v a  2s .co m*/
    db.setAutoCommit(false);
    Statement stat = db.createStatement();
    PrintWriter log = new PrintWriter(new File("checkertest.log"));
    ImportPhagelist.getInstance().parseAllPhagePrimers(bps);
    stat.execute("SET FILES LOG FALSE;\n");
    ResultSet call = stat.executeQuery("Select * From Primerdb.Phages;");
    List<String[]> phages = new ArrayList<>();
    String strain = "";
    while (call.next()) {
        String[] r = new String[3];
        r[0] = call.getString("Strain");
        r[1] = call.getString("Cluster");
        r[2] = call.getString("Name");
        phages.add(r);
        if (r[2].equals("xkcd")) {
            strain = r[0];
        }
    }
    String x = strain;
    phages.stream().filter(y -> y[0].equals(x)).map(y -> y[1]).collect(Collectors.toSet()).forEach(z -> {
        System.out.println("Starting:" + z);
        try {
            List<String> primers = new ArrayList<String>();
            Set<String> clustphages = phages.stream().filter(a -> a[0].equals(x) && a[1].equals(z))
                    .map(a -> a[2]).collect(Collectors.toSet());

            ResultSet resultSet = stat.executeQuery("Select * from primerdb.primers" + " where Strain ='" + x
                    + "' and Cluster ='" + z + "' and UniqueP = true" + " and Bp = " + Integer.valueOf(bps)
                    + " and Hairpin = false");
            while (resultSet.next()) {
                primers.add(resultSet.getString("Sequence"));
            }
            if (primers.size() > 0) {
                for (int i = 0; i < 4; i++) {
                    String primer = primers.get(i);
                    for (String clustphage : clustphages) {
                        if (!CSV.readCSV(base + "/PhageData/" + Integer.toString(bps) + clustphage + ".csv")
                                .contains(primer))
                            log.println("Problem " + z);
                    }
                }
                Set<String> nonclustphages = phages.stream().filter(a -> a[0].equals(x) && !a[1].equals(z))
                        .map(a -> a[2]).collect(Collectors.toSet());
                log.println("Cluster phages done");
                for (int i = 0; i < 4; i++) {
                    String primer = primers.get(i);
                    for (String nonclustphage : nonclustphages) {
                        if (CSV.readCSV(base + "/PhageData/" + Integer.toString(bps) + nonclustphage + ".csv")
                                .contains(primer))
                            log.println("Problem " + z);
                    }
                }
                log.println("NonCluster phages done");
            }
        } catch (SQLException e) {
            e.printStackTrace();
            System.out.println("Error occurred at " + x + " " + z);
        }
        log.println(z);
        log.flush();
        System.gc();
    });
    stat.execute("SET FILES LOG TRUE\n");
    stat.close();
    System.out.println("Primers Matched");
}

From source file:edu.ku.brc.specify.dbsupport.cleanuptools.LocalityCleanup.java

/**
 * //from  www . j  ava  2  s.c  o  m
 */
public static void fixLocality() {
    String connectStr = "jdbc:mysql://localhost/";

    String dbName = "kevin";

    DBConnection dbc = new DBConnection("root", "root", connectStr + dbName, "com.mysql.jdbc.Driver",
            "org.hibernate.dialect.MySQLDialect", dbName);
    Connection conn = dbc.createConnection();
    BasicSQLUtils.setDBConnection(conn);

    try {
        Statement stmt = conn.createStatement();
        PreparedStatement pStmt = conn
                .prepareStatement("UPDATE collectingevent SET LocalityID=? WHERE CollectingEventID = ?");
        PreparedStatement delStmt = conn.prepareStatement("DELETE FROM locality WHERE LocalityID=?");
        PreparedStatement delStmt2 = conn
                .prepareStatement("DELETE FROM localitydetail WHERE LocalityDetailID=?");
        PreparedStatement delStmt3 = conn
                .prepareStatement("DELETE FROM geocoorddetail WHERE GeocoordDetailID=?");

        int fixedCnt = 0;
        String sql = "SELECT LocalityName FROM (SELECT LocalityName, COUNT(LocalityName) as cnt FROM locality GROUP BY LocalityName) T1 WHERE cnt > 1 ORDER BY cnt desc";
        for (Object[] cols : BasicSQLUtils.query(sql)) {
            String locName = cols[0].toString();

            sql = String.format(
                    "SELECT LocalityID FROM locality WHERE LocalityName = '%s' ORDER BY LocalityID ASC",
                    locName);
            System.out.println(
                    "------------------------------------" + locName + "-----------------------------------");

            Integer firstID = null;
            int c = 0;
            ResultSet rs2 = stmt.executeQuery(sql);
            while (rs2.next()) {
                int id = rs2.getInt(1);
                if (c == 0) {
                    firstID = id;
                    c = 1;
                    continue;
                }

                System.out.println("Fixing LocalityID: " + id);
                sql = String.format("SELECT CollectingEventId FROM collectingevent WHERE LocalityID = %d", id);
                Vector<Integer> ids = BasicSQLUtils.queryForInts(conn, sql);
                for (Integer ceId : ids) {
                    pStmt.setInt(1, firstID);
                    pStmt.setInt(2, ceId);
                    if (pStmt.executeUpdate() != 1) {
                        System.out.println("Error updating CE Id: " + ceId);
                    } else {
                        System.out
                                .println("Fixed CollectingEventID: " + ceId + "  with LocalityID: " + firstID);
                        fixedCnt++;
                    }
                }
                c++;

                System.out.println("Fixing LocalityID: " + id);
                sql = String.format("SELECT LocalityDetailID FROM localitydetail WHERE LocalityID = %d", id);
                ids = BasicSQLUtils.queryForInts(conn, sql);
                for (Integer ldId : ids) {
                    delStmt2.setInt(1, ldId);
                    if (delStmt2.executeUpdate() != 1) {
                        System.out.println("Error deleting LocalityDetailID: " + id);
                    } else {
                        System.out.println("Deleted LocalityDetailID: " + id);
                    }
                }

                System.out.println("Fixing GeocoordDetail for: " + id);
                sql = String.format("SELECT GeocoordDetailID FROM geocoorddetail WHERE LocalityID = %d", id);
                ids = BasicSQLUtils.queryForInts(conn, sql);
                for (Integer ldId : ids) {
                    delStmt3.setInt(1, ldId);
                    if (delStmt3.executeUpdate() != 1) {
                        System.out.println("Error deleting GeocoordDetailID: " + id);
                    } else {
                        System.out.println("Deleted GeocoordDetailID: " + id);
                    }
                }

                sql = "SELECT COUNT(*) FROM collectingevent WHERE LocalityID = " + id;
                System.out.println(sql);
                int ceCnt = BasicSQLUtils.getCountAsInt(sql);

                if (ceCnt == 0) {
                    delStmt.setInt(1, id);
                    if (delStmt.executeUpdate() != 1) {
                        System.out.println("Error deleting LocalityID: " + id);
                    } else {
                        System.out.println("Deleted LocalityID: " + id);
                    }
                } else {
                    System.out.println("Can't Delete LocalityID: " + id);
                }
            }
            rs2.close();
        }

        stmt.close();
        pStmt.close();

        System.out.println("Fixed CE Ids: " + fixedCnt);

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

From source file:com.pactera.edg.am.metamanager.extractor.util.GenSqlUtil.java

/**
 * ????Oracle?Teradata?SQL//w ww .  j a  v a 2  s .  co m
 * 
 * @return
 * @throws IOException
 *             ????Bean
 * @throws SQLException
 *             ?????
 */
private static Map<String, String> findDatabaseSQL() {
    Connection conn = null;
    String databaseName = instance.databaseName;
    try {
        if (databaseName == null) {
            DataSource dataSource = ExtractorContextLoader.getDataSource();
            conn = dataSource.getConnection();
            DatabaseMetaData meta = conn.getMetaData();
            instance.databaseName = meta.getDatabaseProductName();
            databaseName = instance.databaseName;
        }
        String location = instance.getLocation(databaseName);
        if (location == null) {
            throw new SQLFileNotLoadException("???" + databaseName
                    + "SQLspring/context-service.xmlGenSqlUtil");
        }

        if (instance.sqlHolder.get(databaseName) == null) {
            Map<String, String> sqls = readSQL(location);
            instance.sqlHolder.put(databaseName, sqls);
        }
        return instance.sqlHolder.get(databaseName);
    } catch (SQLException e) {
        databaseName = (databaseName == null) ? "Unkown" : databaseName;
        String s = "??[" + databaseName + "]SQL";
        log.error(s, e);
        throw new SQLFileNotLoadException(s, e);
    } catch (IOException e) {
        databaseName = (databaseName == null) ? "Unkown" : databaseName;
        String s = "??[" + databaseName + "]SQL";
        log.error(s, e);
        throw new SQLFileNotLoadException(s, e);
    } finally {
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
}

From source file:edu.ku.brc.specify.dbsupport.cleanuptools.LocalityCleanup.java

/**
 * /*w ww .j a v a  2 s  .  c o m*/
 */
public static void fixTaxa() {
    String connectStr = "jdbc:mysql://localhost/";

    String dbName = "kevin";

    DBConnection dbc = new DBConnection("root", "root", connectStr + dbName, "com.mysql.jdbc.Driver",
            "org.hibernate.dialect.MySQLDialect", dbName);
    Connection conn = dbc.createConnection();
    BasicSQLUtils.setDBConnection(conn);

    try {
        // Fix Catalog Numbers
        String sql = "SELECT COUNT(*) FROM collectionobject WHERE CatalogNumber LIKE 'NHRS-COLE %'";
        System.out.println("CatNum to be fixed: " + BasicSQLUtils.getCountAsInt(sql));

        PreparedStatement pTxStmt = conn
                .prepareStatement("UPDATE collectionobject SET CatalogNumber=? WHERE CollectionObjectID = ?");
        sql = "SELECT CatalogNumber, CollectionObjectID FROM collectionobject WHERE CatalogNumber LIKE 'NHRS-COLE %'";
        for (Object[] cols : BasicSQLUtils.query(sql)) {
            String catNum = cols[0].toString();
            catNum = StringUtils.replace(catNum, "COLE ", "COLE");

            pTxStmt.setString(1, catNum);
            pTxStmt.setInt(2, (Integer) cols[1]);

            if (pTxStmt.executeUpdate() != 1) {
                System.out.println("Error deleting ColObjID: " + cols[1]);
            } else {
                System.out.println("Fixed ColObjID: " + cols[1]);
            }
        }
        pTxStmt.close();

        sql = "SELECT COUNT(*) FROM collectionobject WHERE CatalogNumber LIKE 'NHRS-COLE %'";
        System.out.println("CatNum not fixed: " + BasicSQLUtils.getCountAsInt(sql));

        // Fix Taxon - Start by finding all the duplicate Taxon Records
        sql = "SELECT Name FROM (SELECT Name, COUNT(Name) as cnt, TaxonID FROM taxon GROUP BY Name) T1 WHERE cnt > 1 AND TaxonID > 15156 ORDER BY cnt desc";

        Statement stmt = conn.createStatement();
        PreparedStatement pStmt = conn
                .prepareStatement("UPDATE determination SET TaxonID=? WHERE DeterminationID = ?");
        PreparedStatement pStmt2 = conn
                .prepareStatement("UPDATE determination SET PreferredTaxonID=? WHERE DeterminationID = ?");
        PreparedStatement pStmt3 = conn.prepareStatement("UPDATE taxon SET AcceptedID=? WHERE TaxonID = ?");
        PreparedStatement delStmt = conn.prepareStatement("DELETE FROM taxon WHERE TaxonID=?");

        int fixedCnt = 0;
        for (Object[] cols : BasicSQLUtils.query(sql)) {
            String name = cols[0].toString();

            sql = String.format("SELECT COUNT(*) FROM taxon WHERE Name = '%s' ORDER BY TaxonID ASC", name);
            System.out.println("------------------------------------" + name + " - "
                    + BasicSQLUtils.getCountAsInt(sql) + "-----------------------------------");

            // Find all duplicate Taxon Objects
            sql = String.format("SELECT TaxonID FROM taxon WHERE Name = '%s' ORDER BY TaxonID ASC", name);

            int c = 0;
            Integer firstID = null;

            ResultSet rs2 = stmt.executeQuery(sql);
            while (rs2.next()) {
                int id = rs2.getInt(1);
                if (c == 0) // Skip the first one which will the original
                {
                    firstID = id;
                    c = 1;
                    continue;
                }

                // Find all the determinations
                sql = String.format("SELECT DeterminationId FROM determination WHERE TaxonID = %d", id);
                System.out.println(sql);

                Vector<Integer> ids = BasicSQLUtils.queryForInts(conn, sql);
                System.out.println("Fixing " + ids.size() + " determinations with TaxonID: " + id
                        + " Setting to orig TaxonID: " + firstID);
                for (Integer detId : ids) {
                    pStmt.setInt(1, firstID);
                    pStmt.setInt(2, detId);
                    if (pStmt.executeUpdate() != 1) {
                        System.out.println("Error updating DetId: " + detId);
                    } else {
                        System.out.print(detId + ", ");
                        fixedCnt++;
                    }
                }
                System.out.println();

                // Find all the determinations
                sql = String.format("SELECT DeterminationId FROM determination WHERE PreferredTaxonID = %d", id,
                        id);
                System.out.println(sql);

                ids = BasicSQLUtils.queryForInts(conn, sql);
                System.out.println("Fixing " + ids.size() + " determinations with PreferredTaxonID: " + id
                        + " Setting to orig TaxonID: " + firstID);
                for (Integer detId : ids) {
                    pStmt2.setInt(1, firstID);
                    pStmt2.setInt(2, detId);
                    if (pStmt2.executeUpdate() != 1) {
                        System.out.println("Error updating DetId: " + detId);
                    } else {
                        System.out.print(detId + ", ");
                        fixedCnt++;
                    }
                }
                System.out.println();

                sql = String.format("SELECT TaxonID FROM taxon WHERE AcceptedID = %d", id);
                System.out.println(sql);

                ids = BasicSQLUtils.queryForInts(conn, sql);
                System.out.println("Fixing " + ids.size() + " taxon with AcceptedID: " + id
                        + " Setting to orig TaxonID: " + firstID);
                for (Integer taxId : ids) {
                    pStmt3.setInt(1, firstID);
                    pStmt3.setInt(2, taxId);
                    if (pStmt3.executeUpdate() != 1) {
                        System.out.println("Error updating TaxId: " + taxId);
                    } else {
                        System.out.print(taxId + ", ");
                        fixedCnt++;
                    }
                }
                System.out.println();

                sql = "SELECT COUNT(*) FROM taxon WHERE ParentID = " + id;
                System.out.println(sql);

                if (BasicSQLUtils.getCountAsInt(sql) == 0) {
                    delStmt.setInt(1, id);
                    if (delStmt.executeUpdate() != 1) {
                        System.out.println("Error deleting TaxonID: " + id);
                    } else {
                        System.out.println("Deleted TaxonID: " + id);
                    }
                } else {
                    System.out.println("Unable to delete TaxonID: " + id + " it is a parent.");
                }
                c++;
            }
            rs2.close();

            int detCnt = BasicSQLUtils
                    .getCountAsInt("SELECT COUNT(*) FROM determination WHERE TaxonID = " + firstID);
            if (detCnt > 0) {
                System.out.println(detCnt + " Determinations still using TaxonID: " + firstID);
            }
        }

        stmt.close();
        pStmt.close();

        System.out.println("Fixed Det Ids: " + fixedCnt);

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

From source file:azkaban.executor.JdbcExecutorLoaderTest.java

@BeforeClass
public static void setupDB() {
    DataSource dataSource = DataSourceUtils.getMySQLDataSource(host, port, database, user, password,
            numConnections);//from  ww  w  .  j  a va 2  s . com
    testDBExists = true;

    Connection connection = null;
    try {
        connection = dataSource.getConnection();
    } catch (SQLException e) {
        e.printStackTrace();
        testDBExists = false;
        DbUtils.closeQuietly(connection);
        return;
    }

    CountHandler countHandler = new CountHandler();
    QueryRunner runner = new QueryRunner();
    try {
        runner.query(connection, "SELECT COUNT(1) FROM active_executing_flows", countHandler);
    } catch (SQLException e) {
        e.printStackTrace();
        testDBExists = false;
        DbUtils.closeQuietly(connection);
        return;
    }

    try {
        runner.query(connection, "SELECT COUNT(1) FROM execution_flows", countHandler);
    } catch (SQLException e) {
        e.printStackTrace();
        testDBExists = false;
        DbUtils.closeQuietly(connection);
        return;
    }

    try {
        runner.query(connection, "SELECT COUNT(1) FROM execution_jobs", countHandler);
    } catch (SQLException e) {
        e.printStackTrace();
        testDBExists = false;
        DbUtils.closeQuietly(connection);
        return;
    }

    try {
        runner.query(connection, "SELECT COUNT(1) FROM execution_logs", countHandler);
    } catch (SQLException e) {
        e.printStackTrace();
        testDBExists = false;
        DbUtils.closeQuietly(connection);
        return;
    }

    try {
        runner.query(connection, "SELECT COUNT(1) FROM executors", countHandler);
    } catch (SQLException e) {
        e.printStackTrace();
        testDBExists = false;
        DbUtils.closeQuietly(connection);
        return;
    }

    try {
        runner.query(connection, "SELECT COUNT(1) FROM executor_events", countHandler);
    } catch (SQLException e) {
        e.printStackTrace();
        testDBExists = false;
        DbUtils.closeQuietly(connection);
        return;
    }

    DbUtils.closeQuietly(connection);
}

From source file:HSqlManager.java

private static void checkPhage(Connection connection) throws SQLException, IOException {
    List<String[]> all = INSTANCE.readFileAllStrains(INSTANCE.path);
    List<String> clusters = all.stream().map(x -> x[0]).collect(Collectors.toList());
    Set<String> phages = all.stream().map(x -> x[1]).collect(Collectors.toSet());
    List<String> strains = all.stream().map(x -> x[2]).collect(Collectors.toList());
    List<String> phageslist = all.stream().map(x -> x[1]).collect(Collectors.toList());
    Set<String> dbphages = new HashSet<>();
    Statement st = connection.createStatement();
    PreparedStatement insertPhages = connection
            .prepareStatement("INSERT INTO Primerdb.Phages(Name, Cluster, Strain)" + " values(?,?,?);");
    String sql = "SELECT * FROM Primerdb.Phages;";
    ResultSet rs = st.executeQuery(sql);
    while (rs.next()) {
        dbphages.add(rs.getString("Name"));
    }/* w  w w . j  a va  2  s .c o m*/
    phages.removeAll(dbphages);
    List<String[]> phageinfo = new ArrayList<>();
    if (phages.size() > 0) {
        System.out.println("Phages Added:");
        phages.forEach(x -> {
            String[] ar = new String[3];
            System.out.println(x);
            String cluster = clusters.get(phageslist.indexOf(x));
            String strain = strains.get(phageslist.indexOf(x));
            try {
                insertPhages.setString(1, x);
                insertPhages.setString(2, cluster);
                insertPhages.setString(3, strain);
                insertPhages.addBatch();
            } catch (SQLException e) {
                e.printStackTrace();
            }
            try {
                insertPhages.executeBatch();
            } catch (SQLException e) {
                e.printStackTrace();
            }
            ar[0] = x;
            ar[1] = cluster;
            ar[2] = strain;
            phageinfo.add(ar);
        });
        newPhages = phageinfo;
    } else {
        System.out.println("No Phages added");
    }
    st.close();
    insertPhages.close();
}

From source file:HSqlManager.java

private static void commonInitialize(int bps, Connection connection) throws SQLException, IOException {
    String base = new File("").getAbsolutePath();
    CSV.makeDirectory(new File(base + "/PhageData"));
    INSTANCE = ImportPhagelist.getInstance();
    INSTANCE.parseAllPhages(bps);//from   w  ww .jav a 2s  .c  o m
    written = true;
    Connection db = connection;
    db.setAutoCommit(false);
    Statement stat = db.createStatement();
    stat.execute("SET FILES LOG FALSE\n");
    PreparedStatement st = db.prepareStatement("Insert INTO Primerdb.Primers"
            + "(Bp,Sequence, CommonP, UniqueP, Picked, Strain, Cluster)" + " Values(?,?,true,false,false,?,?)");
    ResultSet call = stat.executeQuery("Select * From Primerdb.Phages;");
    List<String[]> phages = new ArrayList<>();
    while (call.next()) {
        String[] r = new String[3];
        r[0] = call.getString("Strain");
        r[1] = call.getString("Cluster");
        r[2] = call.getString("Name");
        phages.add(r);
    }
    phages.parallelStream().map(x -> x[0]).collect(Collectors.toSet()).parallelStream().forEach(x -> {
        phages.stream().filter(y -> y[0].equals(x)).map(y -> y[1]).collect(Collectors.toSet()).forEach(z -> {
            try {
                List<String> clustphages = phages.stream().filter(a -> a[0].equals(x) && a[1].equals(z))
                        .map(a -> a[2]).collect(Collectors.toList());
                Set<String> primers = Collections.synchronizedSet(CSV
                        .readCSV(base + "/PhageData/" + Integer.toString(bps) + clustphages.get(0) + ".csv"));
                clustphages.remove(0);
                clustphages.parallelStream().forEach(phage -> {
                    primers.retainAll(
                            CSV.readCSV(base + "/PhageData/" + Integer.toString(bps) + phage + ".csv"));
                });
                int i = 0;
                for (CharSequence a : primers) {
                    try {
                        //finish update
                        st.setInt(1, bps);
                        st.setString(2, a.toString());
                        st.setString(3, x);
                        st.setString(4, z);
                        st.addBatch();
                    } catch (SQLException e) {
                        e.printStackTrace();
                        System.out.println("Error occurred at " + x + " " + z);
                    }
                    i++;
                    if (i == 1000) {
                        i = 0;
                        st.executeBatch();
                        db.commit();
                    }
                }
                if (i > 0) {
                    st.executeBatch();
                    db.commit();
                }
            } catch (SQLException e) {
                e.printStackTrace();
                System.out.println("Error occurred at " + x + " " + z);
            }
        });
    });
    stat.execute("SET FILES LOG TRUE\n");
    st.close();
    stat.close();
    System.out.println("Common Updated");
}

From source file:egovframework.com.ext.jfile.sample.service.impl.SampleDAO.java

public void testConnection() {
    try {//from   w  ww. j  a  v a2s  . c  om
        if (log.isDebugEnabled()) {
            log.debug(getSqlMapClientTemplate().getDataSource().getConnection());
        }
    } catch (SQLException e) {
        e.printStackTrace();
    }
}

From source file:HSqlManager.java

@SuppressWarnings("Duplicates")
@Deprecated//from   w  w  w.  j ava  2s.c  om
private static void mycoCommonInitialize(int bps, Connection connection) throws SQLException, IOException {
    long time = System.currentTimeMillis();
    String base = new File("").getAbsolutePath();
    CSV.makeDirectory(new File(base + "/PhageData"));
    INSTANCE = ImportPhagelist.getInstance();
    //        INSTANCE.parseAllPhages(bps);
    written = true;
    Connection db = connection;
    db.setAutoCommit(false);
    Statement stat = db.createStatement();
    stat.execute("SET FILES LOG FALSE\n");
    PreparedStatement st = db.prepareStatement("Insert INTO Primerdb.Primers"
            + "(Bp,Sequence, CommonP, UniqueP, Picked, Strain, Cluster)" + " Values(?,?,true,false,false,?,?)");
    ResultSet call = stat.executeQuery("Select * From Primerdb.Phages;");
    List<String[]> phages = new ArrayList<>();
    String strain = "";
    while (call.next()) {
        String[] r = new String[3];
        r[0] = call.getString("Strain");
        r[1] = call.getString("Cluster");
        r[2] = call.getString("Name");
        phages.add(r);
        if (r[2].equals("xkcd")) {
            strain = r[0];
        }
    }
    call.close();
    String x = strain;
    Set<String> clust = phages.stream().filter(y -> y[0].equals(x)).map(y -> y[1]).collect(Collectors.toSet());
    Map<String, List<String>> clusters = new HashMap<>();
    clust.parallelStream().forEach(cluster -> clusters.put(cluster, phages.stream()
            .filter(a -> a[0].equals(x) && a[1].equals(cluster)).map(a -> a[2]).collect(Collectors.toList())));
    for (String z : clusters.keySet()) {
        try {
            List<String> clustphages = clusters.get(z);
            Set<String> primers = Collections.synchronizedSet(
                    CSV.readCSV(base + "/PhageData/" + Integer.toString(bps) + clustphages.get(0) + ".csv"));
            clustphages.remove(0);
            for (String phage : clustphages) {
                //                    String[] seqs = Fasta.parse(base + "/Fastas/" + phage + ".fasta");
                //                    String sequence =seqs[0]+seqs[1];
                //                    Map<String, List<Integer>> seqInd = new HashMap<>();
                //                    for (int i = 0; i <= sequence.length()-bps; i++) {
                //                        String sub=sequence.substring(i,i+bps);
                //                        if(seqInd.containsKey(sub)){
                //                            seqInd.get(sub).add(i);
                //                        }else {
                //                            List<Integer> list = new ArrayList<>();
                //                            list.add(i);
                //                            seqInd.put(sub,list);
                //                        }
                //                    }
                //                    primers = primers.stream().filter(seqInd::containsKey).collect(Collectors.toSet());
                //                    primers =Sets.intersection(primers,CSV.readCSV(base + "/PhageData/"+Integer.toString(bps)
                //                            + phage + ".csv"));
                //                    System.gc();
                //                            String[] seqs = Fasta.parse(base + "/Fastas/" + phage + ".fasta");
                //                            String sequence =seqs[0]+seqs[1];
                //                            primers.stream().filter(sequence::contains);
                primers.retainAll(CSV.readCSV(base + "/PhageData/" + Integer.toString(bps) + phage + ".csv"));
                //                    Set<CharSequence> prim = primers;
                //                    for (CharSequence primer: primers){
                //                        if(seqInd.containsKey(primer)){
                //                            prim.remove(primer);
                //                        }
                //                    }
                //                    primers=prim;
            }
            int i = 0;
            for (String a : primers) {
                try {
                    //finish update
                    st.setInt(1, bps);
                    st.setString(2, a);
                    st.setString(3, x);
                    st.setString(4, z);
                    st.addBatch();
                } catch (SQLException e) {
                    e.printStackTrace();
                    System.out.println("Error occurred at " + x + " " + z);
                }
                i++;
                if (i == 1000) {
                    i = 0;
                    st.executeBatch();
                    db.commit();
                }
            }
            if (i > 0) {
                st.executeBatch();
                db.commit();
            }
        } catch (SQLException e) {
            e.printStackTrace();
            System.out.println("Error occurred at " + x + " " + z);
        }
        System.out.println(z);
    }
    stat.execute("SET FILES LOG TRUE\n");
    st.close();
    stat.close();
    System.out.println("Common Updated");
    System.out.println((System.currentTimeMillis() - time) / Math.pow(10, 3) / 60);
}