List of usage examples for java.sql Connection setAutoCommit
void setAutoCommit(boolean autoCommit) throws SQLException;
From source file:HSqlManager.java
@SuppressWarnings("Duplicates") @Deprecated/*from w w w. ja v a2s . co m*/ 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: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; 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);/* w w w . ja va 2 s. com*/ // 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.china317.gmmp.gmmp_report_analysis.App.java
private static void PtmOverSpeedRecordsStoreIntoDB(Map<String, PtmOverSpeed> overSpeedRecords, ApplicationContext context) {// w w w .ja v a 2 s .com // INSERT INTO // TAB_ALARM_OVERSPEED(LICENCE,BEGIN_TIME,END_TIME,SPEED,IS_END,AREA) // SELECT LICENSE,BEGINTIME,ENDTIME,AVGSPEED,'1',FLAG FROM // ALARMOVERSPEED_REA WHERE BUSINESSTYPE = '2' String sql = ""; Connection conn = null; try { SqlMapClient sc = (SqlMapClient) context.getBean("sqlMapClientPtm"); conn = sc.getDataSource().getConnection(); conn.setAutoCommit(false); Statement st = conn.createStatement(); Iterator<String> it = overSpeedRecords.keySet().iterator(); while (it.hasNext()) { String key = it.next(); PtmOverSpeed pos = overSpeedRecords.get(key); sql = "insert into TAB_ALARM_OVERSPEED " + " (LICENCE,BEGIN_TIME,END_TIME,SPEED,IS_END,AREA) " + " values ('" + pos.getLicense() + "','" + pos.getBeginTime() + "','" + pos.getEndTIme() + "'," + pos.getAvgSpeed() + "," + "1" + "," + pos.getFlag() + ")"; log.info(sql); st.addBatch(sql); } st.executeBatch(); conn.commit(); log.info("[insertIntoDB OverSpeed success!!!]"); } catch (Exception e) { e.printStackTrace(); log.error(sql); } finally { overSpeedRecords.clear(); if (conn != null) { try { conn.close(); } catch (SQLException e) { e.printStackTrace(); } } } }
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 ww. j ava 2s .c om 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:com.china317.gmmp.gmmp_report_analysis.App.java
private static void DgmOverSpeedRecordsStoreIntoDB(Map<String, PtmOverSpeed> overSpeedRecords, ApplicationContext context) {/*from w w w .j av a 2 s . c o m*/ // INSERT INTO // TAB_GPSEVENT_OVERSPEED(VID,TYPE,,BEGIN_TIME,END_TIME,DETAIL,AREA,MAX_SPEED,MIN_SPEED) // SELECT CODE,'overspeed',BEGINTIME,ENDTIME,AVGSPEED,FLAG,MAXSPEED,'' // FROM ALARMOVERSPEED_REA WHERE BUSINESSTYPE = '1' String sql = ""; Connection conn = null; try { SqlMapClient sc = (SqlMapClient) context.getBean("sqlMapClientDgm"); conn = sc.getDataSource().getConnection(); conn.setAutoCommit(false); Statement st = conn.createStatement(); Iterator<String> it = overSpeedRecords.keySet().iterator(); while (it.hasNext()) { String key = it.next(); PtmOverSpeed pos = overSpeedRecords.get(key); sql = "INSERT INTO TAB_GPSEVENT_OVERSPEED (VID,TYPE,BEGIN_TIME,END_TIME,DETAIL,AREA,MAX_SPEED,MIN_SPEED) " + " values ('" + pos.getCode() + "','" + "overspeed" + "','" + pos.getBeginTime() + "','" + pos.getEndTIme() + "'," + pos.getAvgSpeed() + "," + pos.getFlag() + "," + pos.getMaxSpeed() + "," + 0 + ")"; log.info(sql); st.addBatch(sql); } st.executeBatch(); conn.commit(); log.info("[insertIntoDB OverSpeed success!!!]"); } catch (Exception e) { e.printStackTrace(); log.error(sql); } finally { overSpeedRecords.clear(); if (conn != null) { try { conn.close(); } catch (SQLException e) { e.printStackTrace(); } } } }
From source file:com.fpuna.preproceso.PreprocesoTS.java
public static HashMap<String, SessionTS> leerBDtrainingSet(String BD, String sensor) { HashMap<String, SessionTS> SessionsTotal = new HashMap<String, SessionTS>(); String Consulta;/* ww w . jav a 2s . co m*/ Connection c = null; Statement stmt = null; Registro reg = new Registro(); Consulta = "SELECT dat.statusId, dat.sensorName, dat.\"value\", dat.\"timestamp\", lb.\"name\"\n" + "FROM sensor_data AS dat, status AS st, label AS lb\n" + "WHERE dat.statusId = st.\"_id\" AND st.labelId = lb.\"_id\" ORDER BY dat.\"timestamp\""; try { Class.forName("org.sqlite.JDBC"); c = DriverManager.getConnection("jdbc:sqlite:" + path + "sensor.db"); c.setAutoCommit(false); System.out.println("Opened database successfully"); stmt = c.createStatement(); ResultSet rs = stmt.executeQuery(Consulta); while (rs.next()) { reg = new Registro(); reg.setSensor(rs.getString("sensorName")); reg.setTiempo(rs.getTimestamp("timestamp")); String[] values = (rs.getString("value")).split("\\,"); if (values.length == 3) { reg.setValor_x(Double.parseDouble(values[0].substring(1))); reg.setValor_y(Double.parseDouble(values[1])); reg.setValor_z(Double.parseDouble(values[2].substring(0, values[2].length() - 1))); } else if (values.length == 5) { reg.setValor_x(Double.parseDouble(values[0].substring(1))); reg.setValor_y(Double.parseDouble(values[1])); reg.setValor_z(Double.parseDouble(values[2])); reg.setM_1(Double.parseDouble(values[3])); reg.setM_2(Double.parseDouble(values[4].substring(0, values[4].length() - 1))); } if (SessionsTotal.containsKey(rs.getString("statusId"))) { SessionTS s = SessionsTotal.get(rs.getString("statusId")); s.addRegistro(reg); SessionsTotal.replace(rs.getString("statusId"), s); } else { SessionTS s = new SessionTS(); s.setActividad(rs.getString("name")); s.addRegistro(reg); SessionsTotal.put(rs.getString("statusId"), s); } } rs.close(); stmt.close(); c.close(); } catch (ClassNotFoundException | SQLException | NumberFormatException e) { System.err.println("Okapu:" + e.getClass().getName() + ": " + e.getMessage()); System.exit(0); } System.out.println("Operation done successfully"); return SessionsTotal; }
From source file:com.china317.gmmp.gmmp_report_analysis.App.java
private static void LybcOverSpeedRecordsStoreIntoDB(Map<String, PtmOverSpeed> overSpeedRecords, ApplicationContext context) {/*from ww w .java 2 s . c o m*/ // INSERT INTO // TAB_ALARM_OVERSPEED(LICENCE,BEGIN_TIME,END_TIME,SPEED,IS_END,AREA,MAX_SPEED) // SELECT LICENSE,BEGINTIME,ENDTIME,AVGSPEED,'1',FLAG,MAXSPEED FROM // ALARMOVERSPEED_REA WHERE BUSINESSTYPE = '3' String sql = ""; Connection conn = null; try { SqlMapClient sc = (SqlMapClient) context.getBean("sqlMapClientLybc"); conn = sc.getDataSource().getConnection(); conn.setAutoCommit(false); Statement st = conn.createStatement(); Iterator<String> it = overSpeedRecords.keySet().iterator(); while (it.hasNext()) { String key = it.next(); PtmOverSpeed pos = overSpeedRecords.get(key); sql = "insert into TAB_ALARM_OVERSPEED " + " (LICENCE,BEGIN_TIME,END_TIME,SPEED,IS_END,AREA,MAX_SPEED) " + " values ('" + pos.getLicense() + "','" + pos.getBeginTime() + "','" + pos.getEndTIme() + "'," + pos.getAvgSpeed() + "," + "1" + "," + pos.getFlag() + "," + pos.getMaxSpeed() + ")"; log.info(sql); st.addBatch(sql); } st.executeBatch(); conn.commit(); log.info("[insertIntoDB OverSpeed success!!!]"); } catch (Exception e) { e.printStackTrace(); log.error(sql); } finally { overSpeedRecords.clear(); if (conn != null) { try { conn.close(); } catch (SQLException e) { e.printStackTrace(); } } } }
From source file:com.china317.gmmp.gmmp_report_analysis.App.java
private static void DgmEntryExitStoreIntoDB(Map<String, DgmEntryExit> map, ApplicationContext context) { /**//from w w w. ja v a2s . c o m * INSERT INTO TAB_GPSEVENT_ILLEGALENTRYEXIT SELECT * CODE,'illegalEntryExit',BEGIN_TIME,END_TIME,DETAIL,ROAD FROM * ALARMILLEGALEXIT_REA */ String sql = ""; Connection conn = null; try { SqlMapClient sc = (SqlMapClient) context.getBean("sqlMapClientDgm"); conn = sc.getDataSource().getConnection(); conn.setAutoCommit(false); Statement st = conn.createStatement(); Iterator<String> it = map.keySet().iterator(); while (it.hasNext()) { String key = it.next(); DgmEntryExit pos = map.get(key); /* * String sql = "insert into ALARMILLEGALEXIT_REA " + * " (CODE,TYPE,BEGIN_TIME,END_TIME,DETAIL,ROAD) " + " values (" * + "'" + pos.getCode() + "'," + "'" + pos.getType() + "'," + * "'" + pos.getBegin_time() + "'," + "'" + pos.getEnd_time() + * "'," + "'" + pos.getDetail() + "','" + pos.getRoad() + "')"; */ sql = "insert into TAB_GPSEVENT_ILLEGALENTRYEXIT " + " (VID,TYPE,BEGIN_TIME,END_TIME,DETAIL,ROAD) " + " values (" + "'" + pos.getCode() + "'," + "'illegalEntryExit'," + "'" + pos.getBegin_time() + "'," + "'" + pos.getEnd_time() + "'," + "'" + pos.getDetail() + "','" + pos.getRoad() + "')"; log.info(sql); st.addBatch(sql); } st.executeBatch(); conn.commit(); log.info("[insertIntoDB DgmEntryExit success!!!]"); } catch (Exception e) { e.printStackTrace(); log.error(sql); } finally { DgmAnalysisImp.getInstance().getExitMap().clear(); if (conn != null) { try { conn.close(); } catch (SQLException e) { e.printStackTrace(); } } } }
From source file:com.taobao.tddl.jdbc.group.integration.TransactionTest.java
@Test public void springTest() throws Exception { Connection conn = ds.getConnection(); conn.setAutoCommit(false); // Statementcrud Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("select f1,f2 from crud"); assertEquals(stmt.executeUpdate("insert into crud(f1,f2) values(10,'str')"), 1); assertEquals(stmt.executeUpdate("insert into crud(f1,f2) values(10,'str')"), 1); conn.commit();//from w w w . j av a 2s. c o m conn.setAutoCommit(true); rs = stmt.executeQuery("select f1,f2 from crud"); rs.next(); assertEquals(rs.getInt(1), 10); assertEquals(rs.getString(2), "str"); rs.close(); assertEquals(stmt.executeUpdate("delete from crud"), 2); stmt.close(); conn.close(); }
From source file:com.china317.gmmp.gmmp_report_analysis.App.java
private static void IntOutNoneRecordsStoreIntoDB(Map<String, AlarmNoMark> iniOutNoneRecords, ApplicationContext context) {// w w w .j av a 2 s . c om Connection conn = null; String sql = ""; try { SqlMapClient sc = (SqlMapClient) context.getBean("sqlMapClientLybc"); conn = sc.getDataSource().getConnection(); conn.setAutoCommit(false); Statement st = conn.createStatement(); Iterator<String> it = iniOutNoneRecords.keySet().iterator(); while (it.hasNext()) { String key = it.next(); AlarmNoMark pos = iniOutNoneRecords.get(key); sql = "insert into TAB_ALARM_NOMARK " + " (LICENCE,BEGIN_TIME,END_TIME,ROAD) " + " values (" + "'" + pos.getLicense() + "'," + "'" + pos.getBeginTime() + "'," + "'" + pos.getEndTime() + "'," + "'" + pos.getRoad() + "')"; log.info(sql); st.addBatch(sql); } st.executeBatch(); conn.commit(); log.info("[insertIntoDB TAB_ALARM_NOMARK success!!!]"); } catch (Exception e) { e.printStackTrace(); log.error(sql); } finally { iniOutNoneRecords.clear(); if (conn != null) { try { conn.close(); } catch (SQLException e) { e.printStackTrace(); } } } }