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:json.AdminController.java

@RequestMapping(value = "/getAdminListService", method = RequestMethod.GET, produces = "application/json")
public @ResponseBody ArrayList<Admin> getAdmins() {
    Connection conn = null;//from w w  w .j ava 2  s  .  c  o  m
    Statement stmt = null;
    ResultSet rs = null;
    ArrayList<Admin> adminList = new ArrayList();

    try {
        //Set up connection with database
        conn = ConnectionManager.getConnection();
        stmt = conn.createStatement();

        //Execute sql satatement to obtain account from database
        rs = stmt.executeQuery("select * from admin;");

        while (rs != null && rs.next()) {
            String id = rs.getString(1);
            String password = rs.getString(2);
            String email = rs.getString(3);
            String name = rs.getString(4);
            String role = rs.getString(5);

            adminList.add(new Admin(id, password, email, name, role));
        }
    } catch (SQLException ex) {
        ex.printStackTrace();
    } finally {
        ConnectionManager.close(conn, stmt, rs);
    }

    return adminList;
}

From source file:controladores.controladorEmpleados.java

private Connection getConexion() {
    if (this.conexion == null) {
        try {//ww w .  j  a va2  s. c  om
            DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
            this.conexion = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE", "system",
                    "javaoracle");
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
    }
    return this.conexion;
}

From source file:com.jp.systemdirector.projectzero.zab01.ap.logicbean.SZAB011CInsertLogicBean.java

@Transactional
public SZAB011CInsertResultData execute(ContextData context, SZAB011CInsertInputData inputData) {

    SZAB011CInsertResultData resultData = new SZAB011CInsertResultData();

    SZAB011CInsertDTO zInsertDTO = new SZAB011CInsertDTO();

    //DTO?inputData?        
    zInsertDTO.setSTORING_ID(context.getStoringId());
    zInsertDTO.setPRODUCT_CD(context.getProductCd());
    zInsertDTO.setSTORINGQUANTITY(Integer.parseInt(context.getStoringQuantity()));
    zInsertDTO.setSTORING_DATE(context.getStoringDate());
    zInsertDTO.setSTORINGUSER_ID(context.getStoringUserCd());
    zInsertDTO.setREMARKS(context.getRemarks());

    try {//from  w  w  w.  j  a va2 s .c  o  m
        int result = dao.insert(zInsertDTO);

        resultData.setAffectLines(result);
    } catch (SQLException e) {

        e.printStackTrace();
        throw new RuntimeException(e);
    }

    return resultData;
}

From source file:de.rbs90.fwdisp.settingsgui.gui.tabs.statistics.TimeStatisticsPanel.java

public TimeStatisticsPanel() {
    setName("Uhrzeit");

    setLayout(new BorderLayout());

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    int alarmCount[] = new int[24];

    try {/*from www . j  av  a 2s  .  co  m*/
        ResultSet resultSet = Starter.getDatabase().getStatement().executeQuery(
                "SELECT STARTTIME_HOUR, COUNT(*) AS COUNT FROM ALARMHISTORY GROUP BY STARTTIME_HOUR");

        while (resultSet.next()) {
            alarmCount[resultSet.getInt("STARTTIME_HOUR")] = resultSet.getInt("COUNT");
        }

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

    for (int i = 0; i < 24; i++) {
        dataset.addValue(alarmCount[i], "", "" + i);
    }

    JFreeChart chart = ChartFactory.createBarChart3D("Zeitbersicht", "Uhrzeit", "Einstze", dataset,
            PlotOrientation.VERTICAL, false, false, false);

    chart.setBackgroundPaint(getBackground());

    ChartPanel panel = new ChartPanel(chart);
    panel.setPopupMenu(null);
    add(panel, BorderLayout.CENTER);
}

From source file:de.rbs90.fwdisp.settingsgui.gui.tabs.statistics.MonthlyStatisticPanel.java

public MonthlyStatisticPanel() {
    setName("Monat");
    setLayout(new BorderLayout());

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    int alarmCount[] = new int[12];

    try {//from ww w  . j a  v  a2 s .com
        ResultSet resultSet = Starter.getDatabase().getStatement().executeQuery(
                "SELECT STARTDATE_MONTH, COUNT(*) AS COUNT FROM ALARMHISTORY GROUP BY STARTDATE_MONTH");

        while (resultSet.next()) {
            alarmCount[resultSet.getInt("STARTDATE_MONTH") - 1] = resultSet.getInt("COUNT");
        }

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

    for (int i = 0; i < 12; i++) {
        dataset.addValue(alarmCount[i], "", "" + (i + 1));
    }

    JFreeChart chart = ChartFactory.createBarChart3D("Monatsbersicht", "Monat", "Einstze", dataset,
            PlotOrientation.VERTICAL, false, false, false);

    chart.setBackgroundPaint(getBackground());
    ChartPanel panel = new ChartPanel(chart);
    panel.setPopupMenu(null);

    add(panel, BorderLayout.CENTER);
}

From source file:json.AnalyticsController.java

@RequestMapping(value = "/getStatusBreakdownByBusinessUnit/{businessUnit}", method = RequestMethod.GET, produces = "application/json")
public @ResponseBody StatusBreakdownResponse getStatusBreakdownByBusinessUnit(
        @PathVariable("businessUnit") String businessUnit) {
    Connection conn = null;/*from   w w w . j  av  a 2 s .c om*/
    Statement stmt = null;
    ResultSet rs = null;
    ArrayList<Jobs> jobList = new ArrayList();

    int pending = 0;
    int reviewed = 0;

    try {
        //Set up connection with database
        conn = ConnectionManager.getConnection();
        stmt = conn.createStatement();

        //Execute sql satatement to obtain jobs from database
        rs = stmt.executeQuery(
                "select a.status from job j inner join application a on j.jobID = a.jobIDApplied and j.businessUnit = '"
                        + businessUnit + "';");

        while (rs != null && rs.next()) {
            String status = rs.getString(1);

            switch (status) {
            case "Pending":
                pending++;
                break;
            case "Reviewed":
                reviewed++;
                break;
            }
        }
    } catch (SQLException ex) {
        ex.printStackTrace();
    } finally {
        ConnectionManager.close(conn, stmt, rs);
    }

    return new StatusBreakdownResponse(pending, reviewed);
}

From source file:HSqlManager.java

public static void primerAnalysis(Connection connection, int bps) throws SQLException, IOException {
    long time = System.currentTimeMillis();
    DpalLoad.main(new String[1]);
    HSqlPrimerDesign.Dpal_Inst = DpalLoad.INSTANCE_WIN64;
    String base = new File("").getAbsolutePath();
    CSV.makeDirectory(new File(base + "/PhageData"));
    INSTANCE = ImportPhagelist.getInstance();
    INSTANCE.parseAllPhages(bps);//  w  w  w  . j a  v  a 2 s . co m
    System.out.println((System.currentTimeMillis() - time) / Math.pow(10, 3) / 60);
    time = System.currentTimeMillis();
    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,?,?)");
    PreparedStatement st = db.prepareStatement(
            "INSERT INTO Primerdb.Primers" + "(Bp,Sequence,Strain,Cluster,Tm,GC,UniqueP,CommonP,Hairpin) "
                    + "VALUES(?,?,?,?,?,?,true,true,?)");
    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);

        //            if(strain.equals("-myco")) {
        //                if (r[2].equals("xkcd")) {
        //                    strain = r[0];
        //                }
        //            }else if(strain.equals("-arthro")){
        //                if (r[2].equals("ArV1")) {
        //                    strain = r[0];
        //                }
        //            }
    }
    call.close();

    Set<String> strains = phages.stream().map(y -> y[0]).collect(Collectors.toSet());
    for (String x : strains) {
        Set<String> clust = phages.stream().filter(y -> y[0].equals(x)).map(y -> y[1])
                .collect(Collectors.toSet());
        Map<String, Integer> clustersNum = new HashMap<>();
        Map<Integer, String> clustersName = new HashMap<>();
        Map<Integer, List<String>> clusters = new HashMap<>();
        Map<Bytes, Primer> primers = new HashMap<>();
        int i = 0;
        for (String cluster : clust) {
            clustersName.put(i, cluster);
            clustersNum.put(cluster, i);
            i++;
        }
        clust.parallelStream()
                .forEach(cluster -> clusters.put(clustersNum.get(cluster),
                        phages.stream().filter(a -> a[0].equals(x) && a[1].equals(cluster)).map(a -> a[2])
                                .collect(Collectors.toList())));
        for (int z : clusters.keySet()) {
            //            try {
            List<String> clustphages = clusters.get(z);
            for (String phage : clustphages) {
                Set<Bytes> phagprimers =
                        //Read from CSV file here
                        //Premade CSV files of all possible
                        //primers in a phage genome
                        CSV.readCSV(base + "/PhageData/" + Integer.toString(bps) + phage + ".csv").stream()
                                .map(l -> new Bytes(l.getBytes())).collect(Collectors.toSet());
                for (Bytes primer : phagprimers) {
                    if (!primers.containsKey(primer)) {
                        primers.put(primer, new Primer(z));
                    } else {
                        Primer select = primers.get(primer);
                        select.phageCount++;
                        if (!select.containsCluster(z)) {
                            select.addCluster(z);
                        }
                    }

                }

            }
            System.out.println(clustersName.get(z));
        }
        int count = 0;
        Iterator<Map.Entry<Bytes, Primer>> primersSet = primers.entrySet().iterator();
        while (primersSet.hasNext()) {
            Map.Entry<Bytes, Primer> primer = primersSet.next();
            Primer primerInf = primer.getValue();
            if (primerInf.clusters.length != 1) {
                primer.setValue(null);
            } else {
                int primerClust = -1;
                for (int cluster : primerInf.clusters) {
                    primerClust = cluster;
                }
                if (primerInf.phageCount != clusters.get(primerClust).size()) {
                    primer.setValue(null);
                } else {
                    count++;
                }
            }
        }
        System.out.print("Unique Count: ");
        System.out.println(count);
        System.out.print("Primer Count: ");
        System.out.println(primers.size());
        i = 0;
        for (Bytes a : primers.keySet()) {
            Primer primerInf = primers.get(a);
            if (primerInf != null) {
                String primerClust = "";
                for (int cluster : primerInf.clusters) {
                    primerClust = clustersName.get(cluster);
                }
                String str = new String(a.bytes);
                try {
                    st.setInt(1, bps);
                    st.setString(2, str);
                    st.setString(3, x);
                    st.setString(4, primerClust);
                    //                        st.setDouble(5, HSqlPrimerDesign.primerTm(str, 0, 800, 1.5, 0.2));
                    st.setDouble(5, HSqlPrimerDesign.easytm(str));
                    st.setDouble(6, HSqlPrimerDesign.gcContent(str));
                    st.setBoolean(7, HSqlPrimerDesign.calcHairpin(str, 4));
                    st.addBatch();
                } catch (SQLException e) {
                    e.printStackTrace();
                    System.out.println("Error occurred at " + x + " " + primerClust);
                }
                i++;
                if (i == 1000) {
                    i = 0;
                    st.executeBatch();
                    db.commit();
                }
            }
        }
        if (i > 0) {
            st.executeBatch();
            db.commit();
        }

        //        }

        System.out.println("Unique Updated");
        System.out.println((System.currentTimeMillis() - time) / Math.pow(10, 3) / 60);
    }
    stat.execute("SET FILES LOG TRUE;");
    st.close();
    stat.close();
}

From source file:edu.secprog.db.DBPool.java

public Connection getConnection() {
    try {/*from  w  ww . j  a v a2s. c  om*/
        return dataSource.getConnection();

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

From source file:com.dangdang.ddframe.rdb.transaction.soft.base.AbstractSoftTransactionIntegrationTest.java

private void createTable(final ShardingDataSource shardingDataSource) throws SQLException {
    String dbSchema = "CREATE TABLE IF NOT EXISTS `transaction_test` (" + "`id` int NOT NULL, "
            + "PRIMARY KEY (`id`));";
    try (Connection conn = shardingDataSource.getConnection().getConnection("db_trans",
            SQLStatementType.SELECT); PreparedStatement preparedStatement = conn.prepareStatement(dbSchema)) {
        preparedStatement.executeUpdate();
    } catch (final SQLException e) {
        e.printStackTrace();
    }//from w  ww  .j a v a2 s .  co  m
}

From source file:com.level3.tca.schema.migration.ResourceMgr.java

public ResourceMgr(Connection conn) {
    try (ResultSet rs = Db.getResources(conn)) {
        while (rs.next()) {
            String circuitId = rs.getString("circuit_id");
            String uuid = rs.getString("uuid");
            resources.put(makeResourceKey(circuitId, uuid), Util.uuidFromSeed());
        }//www  .  j a v a  2 s.  c o m

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

}