List of usage examples for java.sql SQLException printStackTrace
public void printStackTrace()
From source file:cognition.pipeline.data.helper.ClobHelper.java
private String getString(Object expectedClob) { SerializableClobProxy clobProxy = (SerializableClobProxy) Proxy.getInvocationHandler(expectedClob); Clob wrappedClob = clobProxy.getWrappedClob(); try {/*from w ww.ja va2 s. c o m*/ return wrappedClob.getSubString(1, (int) wrappedClob.length()); } catch (SQLException e) { e.printStackTrace(); return "error: could not retrieve text"; } }
From source file:HSqlManager.java
@SuppressWarnings("Duplicates") @Deprecated/* ww w .ja v a2s . com*/ public static void mycoUniqueDB(Connection connection, int bps) throws ClassNotFoundException, SQLException, InstantiationException, IllegalAccessException, IOException { long time = System.currentTimeMillis(); DpalLoad.main(new String[1]); HSqlPrimerDesign.Dpal_Inst = DpalLoad.INSTANCE_WIN64; String base = new File("").getAbsolutePath(); if (!written) { CSV.makeDirectory(new File(base + "/PhageData")); INSTANCE.parseAllPhages(bps); } Connection db = connection; db.setAutoCommit(false); Statement stat = db.createStatement(); PrintWriter log = new PrintWriter(new File("javalog.log")); stat.execute("SET FILES LOG FALSE;\n"); PreparedStatement st = db .prepareStatement("UPDATE Primerdb.Primers" + " SET UniqueP = true, Tm = ?, GC =?, Hairpin =?" + "WHERE Cluster = ? and Strain = ? and " + "Sequence = ? and Bp = ?"); 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()); String[] clusters = clust.toArray(new String[clust.size()]); for (String z : clusters) { try { Set<String> nonclustphages = phages.stream().filter(a -> a[0].equals(x) && !a[1].equals(z)) .map(a -> a[2]).collect(Collectors.toSet()); ResultSet resultSet = stat.executeQuery( "Select Sequence from primerdb.primers" + " where Strain ='" + x + "' and Cluster ='" + z + "' and CommonP = true" + " and Bp = " + Integer.valueOf(bps) + " "); Set<CharSequence> primers = Collections.synchronizedSet(new HashSet<>()); while (resultSet.next()) { primers.add(resultSet.getString("Sequence")); } resultSet.close(); for (String phage : nonclustphages) { // 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(primer->!seqInd.containsKey(primer)).collect(Collectors.toSet()); // primers =Sets.difference(primers,CSV.readCSV(base + "/PhageData/"+Integer.toString(bps) // + phage + ".csv")); CSV.readCSV(base + "/PhageData/" + Integer.toString(bps) + phage + ".csv").stream() .filter(primers::contains).forEach(primers::remove); // System.gc(); } int i = 0; for (CharSequence a : primers) { try { st.setDouble(1, HSqlPrimerDesign.primerTm(a, 0, 800, 1.5, 0.2)); st.setDouble(2, HSqlPrimerDesign.gcContent(a)); st.setBoolean(3, HSqlPrimerDesign.calcHairpin((String) a, 4)); st.setString(4, z); st.setString(5, x); st.setString(6, a.toString()); st.setInt(7, bps); 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); } log.println(z); log.flush(); System.gc(); } stat.execute("SET FILES LOG TRUE\n"); st.close(); stat.close(); System.out.println("Unique Updated"); System.out.println((System.currentTimeMillis() - time) / Math.pow(10, 3) / 60); }
From source file:Data.java
/** * Creates a dataset, consisting of two series of monthly data. * * @return The dataset.//from w w w . j a v a2 s .com * @throws ClassNotFoundException */ private static XYDataset createDataset(Statement stmt) throws ClassNotFoundException { TimeSeries s1 = new TimeSeries("Humidit"); TimeSeries s2 = new TimeSeries("Temprature"); ResultSet rs = null; try { String sqlRequest = "SELECT * FROM `t_temphum`"; rs = stmt.executeQuery(sqlRequest); Double hum; Double temp; Timestamp date; while (rs.next()) { hum = rs.getDouble("tmp_humidity"); temp = rs.getDouble("tmp_temperature"); date = rs.getTimestamp("tmp_date"); if (tempUnit == "F") { temp = celsiusToFahrenheit(temp.toString()); } if (date != null) { s1.add(new Second(date), hum); s2.add(new Second(date), temp); } else { JOptionPane.showMessageDialog(panelPrincipal, "Il manque une date dans la dase de donne", "Date null", JOptionPane.WARNING_MESSAGE); } } rs.close(); } catch (SQLException e) { String exception = e.toString(); if (e.getErrorCode() == 0) { JOptionPane.showMessageDialog(panelPrincipal, "Le serveur met trop de temps rpondre ! Veuillez rssayer plus tard ou contacter un administrateur", "Connection timed out", JOptionPane.ERROR_MESSAGE); } else { JOptionPane.showMessageDialog(panelPrincipal, "Voici l'exception : " + exception, "Titre : exception", JOptionPane.ERROR_MESSAGE); // TODO Auto-generated catch block e.printStackTrace(); } } catch (Exception e) { String exception = e.toString(); JOptionPane.showMessageDialog(panelPrincipal, "Voici l'exception : " + exception, "Titre : exception", JOptionPane.ERROR_MESSAGE); e.printStackTrace(); } // ****************************************************************** // More than 150 demo applications are included with the JFreeChart // Developer Guide...for more information, see: // // > http://www.object-refinery.com/jfreechart/guide.html // // ****************************************************************** TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(s1); dataset.addSeries(s2); return dataset; }
From source file:com.musala.core.RssManager.java
@PostConstruct public void startServer() { //TODO For testing purposes only, to be deleted Server server = null;/*from w ww.j a v a 2 s .c om*/ try { server = Server.createTcpServer().start(); } catch (SQLException e) { e.printStackTrace(); } logger.info("Server started and connection is open."); logger.info("URL: jdbc:h2:" + server.getURL() + "/mem:test"); }
From source file:ca.qc.adinfo.rouge.server.DBManager.java
public void disconnect() { try {/*from ww w .ja v a 2 s.c om*/ this.dataSource.close(); } catch (SQLException e) { e.printStackTrace(); } }
From source file:cognition.pipeline.data.helper.BlobHelper.java
private byte[] getBytesFromSerializableBlob(Object serializableBlobProxy) { SerializableBlobProxy blobProxy = (SerializableBlobProxy) Proxy.getInvocationHandler(serializableBlobProxy); Blob wrappedBlob = blobProxy.getWrappedBlob(); try {//from w w w . j ava2s . c o m byte[] bytes = wrappedBlob.getBytes(1, (int) wrappedBlob.length()); if (bytes != null) { if (bytes.length == 0) { return null; } } return bytes; } catch (SQLException e) { e.printStackTrace(); } return null; }
From source file:HSqlPrimerDesign.java
@SuppressWarnings("Duplicates") public static void locations(Connection connection) throws ClassNotFoundException, SQLException, InstantiationException, IllegalAccessException, IOException { long time = System.nanoTime(); String base = new File("").getAbsolutePath(); DpalLoad.main(new String[0]); Dpal_Inst = DpalLoad.INSTANCE_WIN64; System.out.println(Dpal_Inst); Connection db = connection;/*from w w w . j av a 2 s. c o m*/ db.setAutoCommit(false); Statement stat = db.createStatement(); PrintWriter log = new PrintWriter(new File("javalog.log")); stat.execute("SET FILES LOG FALSE;"); PreparedStatement st = db.prepareStatement("INSERT INTO Primerdb.MatchedPrimers(" + "Primer, PrimerMatch, Comp,FragAVG,FragVAR,H2SD,L2SD, Cluster, Strain)" + "Values(?,?,?,?,?,?,?,?,?)"); 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()); String[] clusters = clust.toArray(new String[clust.size()]); // String z ="A1"; for (String z : clusters) { System.out.println("Starting:" + z); List<Primer> primers = new ArrayList<>(); Set<Matches> matched = new HashSet<>(); Set<String> clustphage = phages.stream().filter(a -> a[0].equals(x) && a[1].equals(z)) .map(a -> a[2]).collect(Collectors.toSet()); String[] clustphages = clustphage.toArray(new String[clustphage.size()]); if (clustphages.length > 1) { try { ResultSet resultSet = stat .executeQuery("Select * from primerdb.primers" + " where Strain ='" + x + "' and Cluster ='" + z + "' and UniqueP = true" + " and Hairpin = false"); while (resultSet.next()) { Primer primer = new Primer(resultSet.getString("Sequence")); primer.setTm(resultSet.getDouble("Tm")); primers.add(primer); } resultSet.close(); } catch (SQLException e) { e.printStackTrace(); System.out.println("Error occurred at " + x + " " + z); } System.out.println(primers.size()); Set<Primer> primerlist2 = primers.stream().collect(Collectors.toSet()); Primer[] primers2 = primerlist2.toArray(new Primer[primerlist2.size()]); Map<String, Map<CharSequence, List<Integer>>> locations = Collections .synchronizedMap(new HashMap<>()); clustphage.stream().forEach(phage -> { 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() - 10; i++) { String sub = sequence.substring(i, i + 10); if (seqInd.containsKey(sub)) { seqInd.get(sub).add(i); } else { List<Integer> list = new ArrayList<>(); list.add(i); seqInd.put(sub, list); } } Map<CharSequence, List<Integer>> alllocs = new HashMap<>(); for (Primer primer : primers2) { List<Integer> locs = new ArrayList<>(); String sequence1 = primer.getSequence(); String frag = sequence1.substring(0, 10); List<Integer> integers = seqInd.get(frag); if (integers != null) { for (Integer i : integers) { if ((sequence1.length() + i) < sequence.length() && sequence.substring(i, sequence1.length() + i).equals(sequence1)) { locs.add(i); } } } alllocs.put(sequence1, locs); } locations.put(phage, alllocs); }); System.out.println("locations found"); System.out.println((System.nanoTime() - time) / Math.pow(10, 9) / 60.0); final int[] k = new int[] { 0 }; primerlist2.parallelStream().forEach(a -> { int matches = 0; int i = 0; while (primers2[i] != a) { i++; } for (int j = i + 1; j < primers2.length; j++) { double[] frags = new double[clustphages.length]; int phageCounter = 0; Primer b = primers2[j]; boolean match = true; if (matches > 0) { break; } if (Math.abs(a.getTm() - b.getTm()) > 5.0 || a.getSequence().equals(b.getSequence())) { continue; } for (String phage : clustphages) { List<Integer> loc1 = locations.get(phage).get(a.getSequence()); List<Integer> loc2 = locations.get(phage).get(b.getSequence()); // if(loc1.size()==0){ // System.out.println(phage+" "+a.getSequence()); // } if (loc1.size() == 0 || loc2.size() == 0) { // if (loc1.size()!=1||loc2.size()!=1){ match = false; break; } boolean found = false; int fragCount = 0; int l1 = loc1.get(0); int l2 = loc2.get(0); int count1 = 0; int count2 = 0; int frag = Math.abs(l1 - l2); while (!found) { if (frag >= 500 && frag <= 2000) { fragCount++; if (++count1 < loc1.size()) l1 = loc1.get(count1); else if (++count2 < loc2.size()) l2 = loc2.get(count2); } else if (l1 < l2 && frag < 500) { count2++; } else if (l1 > l2 && frag < 500) { count1++; } else if (l1 > l2 && frag > 2000) { count2++; } else if (l1 < l2 && frag > 2000) { count1++; } else { break; } if (count1 < loc1.size() && count2 < loc2.size()) { l1 = loc1.get(count1); l2 = loc2.get(count2); frag = Math.abs(l1 - l2); } else { if (fragCount == 1) { found = true; frags[phageCounter++] = frag + 0.0; } else { break; } } } if (!found) { match = false; break; } } if (match) { matches++; matched.add(new Matches(a, b, frags)); } } // k[0]++; // System.out.println(k[0]); }); System.out.println((System.nanoTime() - time) / Math.pow(10, 9) / 60.0); System.out.println("Primers matched"); int c = 0; int i = 0; try { for (Matches primerkey : matched) { c++; String primer1 = primerkey.one.getSequence(); String primer2 = primerkey.two.getSequence(); st.setString(1, primer1); st.setString(2, primer2); st.setDouble(3, complementarity(primer1, primer2, Dpal_Inst)); st.setDouble(4, primerkey.stats.getMean()); st.setDouble(5, primerkey.stats.getVariance()); st.setDouble(6, primerkey.stats.getMean() + 2 * primerkey.stats.getStandardDeviation()); st.setDouble(7, primerkey.stats.getMean() - 2 * primerkey.stats.getStandardDeviation()); st.setString(8, z); st.setString(9, x); st.addBatch(); 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(c); } log.println(z); log.flush(); System.gc(); } } stat.execute("SET FILES LOG TRUE;"); st.close(); stat.close(); System.out.println("Matches Submitted"); }
From source file:com.hendisantika.pasien.domain.PasienIdGenerator.java
public Serializable generate(SessionImplementor session, Object object) throws HibernateException { String prefix = "PAS-"; // String prefix = "1500"; Connection connection = session.connection(); try {//from ww w . jav a 2 s.c o m PreparedStatement ps = connection .prepareStatement("SELECT MAX(pasien_id) as value from db_pasien.pasien2"); ResultSet rs = ps.executeQuery(); if (rs.next()) { int id = rs.getInt("value") + 1; // String id = rs.getString("value") + 1; String code = prefix + new Integer(id); // String code = prefix + id; // String code = prefix + StringUtils.leftPad("" + id, 3, '0'); System.out.println("Generated pasienId: " + code); return code; } } catch (SQLException e) { e.printStackTrace(); } return null; }
From source file:gemlite.testing.util.DBManager.java
private boolean checkConnection(BasicDataSource dataSource) { try {/*from www. j a v a 2s . co m*/ Connection conn = dataSource.getConnection(); conn.close(); } catch (SQLException e) { e.printStackTrace(); return false; } return true; }
From source file:com.jp.systemdirector.projectzero.zab01.ap.logicbean.SZAB011CUpdateLogicBean.java
@Transactional public SZAB011CUpdateResultData execute(ContextData context, SZAB011CUpdateInputData inputData) { SZAB011CUpdateResultData resultData = new SZAB011CUpdateResultData(); SZAB011CUpdateDTO zUpdateDTO = new SZAB011CUpdateDTO(); // DTO?inputData? zUpdateDTO.setIN1(context.getProductCd()); zUpdateDTO.setQUANTITY(new BigDecimal(context.getQuantity())); try {//from w ww .ja va 2s.co m int result = dao.update(zUpdateDTO); resultData.setAffectLines(result); } catch (SQLException e) { e.printStackTrace(); throw new RuntimeException(e); } return resultData; }