List of usage examples for java.sql Connection setAutoCommit
void setAutoCommit(boolean autoCommit) throws SQLException;
From source file:com.china317.gmmp.gmmp_report_analysis.App.java
private static void InOutMoreRecordsStoreIntoDB(Map<String, AlarmMore> iniOutMoreRecords, ApplicationContext context) {//from w ww . ja v a2 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 = iniOutMoreRecords.keySet().iterator(); while (it.hasNext()) { String key = it.next(); AlarmMore pos = iniOutMoreRecords.get(key); sql = "insert into TAB_ALARM_MORE " + " (LICENCE,denoter,fisrt_Time,BEGIN_TIME,END_TIME,road) " + " values (" + "'" + pos.getLicense() + "'," + "'" + pos.getDenoter() + "'," + "'" + pos.getFirstTime() + "'," + "'" + pos.getBeginTime() + "'," + "'" + pos.getEndTime() + "'," + "'" + pos.getRoad() + "')"; log.info(sql); st.addBatch(sql); } st.executeBatch(); conn.commit(); log.info("[insertIntoDB TAB_ALARM_MORE success!!!]"); } catch (Exception e) { e.printStackTrace(); log.error(sql); } finally { iniOutMoreRecords.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 OverSpeedRecordsStoreIntoDB(Map<String, PtmOverSpeed> overSpeedRecords, ApplicationContext context) {//from ww w . j a v a 2s. c o m Connection conn = null; String sql = ""; try { SqlMapClient sc = (SqlMapClient) context.getBean("sqlMapClient1"); 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 ALARMOVERSPEED_REA " + " (CODE,LICENSE,LICENSECOLOR,BEGINTIME,ENDTIME,AVGSPEED,MAXSPEED,FLAG,BUSINESSTYPE) " + " values (" + "'" + pos.getCode() + "'," + "'" + pos.getLicense() + "'," + "'" + pos.getLicenseColor() + "'," + "'" + pos.getBeginTime() + "'," + "'" + pos.getEndTIme() + "'," + pos.getAvgSpeed() + "," + pos.getMaxSpeed() + "," + pos.getFlag() + "," + pos.getBusinessType() + ")"; 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:mx.com.pixup.portal.dao.ArchivoBaseParserDaoJdbc.java
public void parserXML() { try {//from w w w .jav a 2 s . co m //variables BD String sql = "INSERT INTO LATABLA VALUES (?)"; PreparedStatement preparedStatement; Connection connection = dataSource.getConnection(); connection.setAutoCommit(false); //se obtiene elemento raiz //elementos 2do nivel //construye parametros de la query //preparedStatement = connection.prepareStatement(sql); // preparedStatement.setInt(1, valor); // preparedStatement.execute(); connection.commit(); } catch (Exception e) { //*** se quit el return porque el mtodo es void System.out.println(e.getMessage()); } }
From source file:com.china317.gmmp.gmmp_report_analysis.App.java
private static void DgmFobbidenStoreIntoDB(Map<String, DgmForbidden> map, ApplicationContext context) { /**// w w w .j a v a 2 s . c o m * INSERT INTO TAB_GPSEVENT_AREA SELECT * CODE,ALARMTYPE,BEGINTIME,ENDTIME,'' FROM ALARMFOBBIDEN_REA */ Connection conn = null; String sql = ""; 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(); DgmForbidden pos = map.get(key); /* * String sql = "insert into ALARMFOBBIDEN_REA " + * " (CODE,LICENSE,LICENSECOLOR,ALARMTYPE,BEGINTIME,ENDTIME) " + * " values (" + "'" + pos.getCode() + "'," + "'" + * pos.getLicense() + "'," + "'" + pos.getLicenseColor() + "'," * + "'" + pos.getAlarmType() + "'," + "'" + pos.getBeginTime() * + "','" + pos.getEndTime() + "')"; */ sql = "insert into TAB_GPSEVENT_AREA " + " (VID,TYPE,BEGIN_TIME,END_TIME,DETAIL) " + " values (" + "'" + pos.getCode() + "'," + "'" + pos.getAlarmType() + "'," + "'" + pos.getBeginTime() + "'," + "'" + pos.getEndTime() + "'," + "'" + "')"; log.info(sql); st.addBatch(sql); } st.executeBatch(); conn.commit(); log.info("[insertIntoDB DgmForbidden success!!!]"); } catch (Exception e) { e.printStackTrace(); log.error(sql); } finally { DgmAnalysisImp.getInstance().getForbiddeningMap().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 DgmIllegalParkingStoreIntoDB(Map<String, DgmIllegalParking> map, ApplicationContext context) {// ww w . ja v a 2 s . c om /* * INSERT INTO TAB_GPSEVENT_ILLEGALPARKING SELECT * CODE,'illegalParking',BEGIN_TIME,END_TIME,'',FLAG FROM * ALARMILLEGALPARKING_REA */ Connection conn = null; String sql = ""; 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(); DgmIllegalParking pos = map.get(key); /* * String sql = "insert into TAB_GPSEVENT_ILLEGALPARKING " + * " (CODE,LICENSE,TYPE,BEGINTIME,ENDTIME,FLAG) " + " values (" * + "'" + pos.getCode() + "'," + "'" + pos.getLicense() + "'," * + "'" + pos.getType() + "'," + "'" + pos.getBeginTime() + * "'," + "'" + pos.getEndTime() + "','" + pos.getFlag() + "')"; */ sql = "insert into TAB_GPSEVENT_ILLEGALPARKING " + " (VID,TYPE,BEGIN_TIME,END_TIME,DETAIL,IS_END) " + " values (" + "'" + pos.getCode() + "'," + "'" + pos.getType() + "'," + "'" + pos.getBeginTime() + "'," + "'" + pos.getEndTime() + "'," + "'" + "'," + pos.getFlag() + ")"; log.info(sql); st.addBatch(sql); } st.executeBatch(); conn.commit(); log.info("[insertIntoDB DgmIllegalParking success!!!]"); } catch (Exception e) { e.printStackTrace(); log.error(sql); } finally { DgmAnalysisImp.getInstance().getIllegalParking().clear(); if (conn != null) { try { conn.close(); } catch (SQLException e) { e.printStackTrace(); } } } }
From source file:hermes.store.jdbc.JDBCConnectionPool.java
protected Connection makeObject() throws HermesException { try {// w ww .ja va 2 s .c o m Connection connection = DriverManager.getConnection(url); connection.setAutoCommit(autoCommit); connection.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED); return connection; } catch (Exception e) { log.error(e.getMessage(), e); throw new HermesException(e); } }
From source file:eagle.storage.jdbc.entity.impl.JdbcEntityUpdaterImpl.java
@Override public int update(List<E> entities) throws Exception { ConnectionManager cm = ConnectionManagerFactory.getInstance(); TorqueStatementPeerImpl<E> peer = cm.getStatementExecutor(this.jdbcEntityDefinition.getJdbcTableName()); Connection connection = cm.getConnection(); connection.setAutoCommit(false); StopWatch stopWatch = new StopWatch(); stopWatch.start();//w w w . jav a 2 s .c o m int num = 0; try { for (E entity : entities) { String primaryKey = entity.getEncodedRowkey(); PrimaryKeyCriteriaBuilder pkBuilder = new PrimaryKeyCriteriaBuilder(Arrays.asList(primaryKey), this.jdbcEntityDefinition.getJdbcTableName()); Criteria selectCriteria = pkBuilder.build(); if (LOG.isDebugEnabled()) LOG.debug("Updating by query: " + SqlBuilder.buildQuery(selectCriteria).getDisplayString()); ColumnValues columnValues = JdbcEntitySerDeserHelper.buildColumnValues(entity, this.jdbcEntityDefinition); num += peer.delegate().doUpdate(selectCriteria, columnValues, connection); } if (LOG.isDebugEnabled()) LOG.debug("Committing updates"); connection.commit(); } catch (Exception ex) { LOG.error("Failed to update, rolling back", ex); connection.rollback(); throw ex; } finally { stopWatch.stop(); if (LOG.isDebugEnabled()) LOG.debug("Closing connection"); connection.close(); } LOG.info(String.format("Updated %s records in %s ms", num, stopWatch.getTime())); return num; }
From source file:mx.com.pixup.portal.dao.CancionParserDaoJdbc.java
public void parserXML() { try {/*from w w w . j a v a 2 s .co m*/ //variables BD String sql = "INSERT INTO cancion VALUES (?,?,?)"; //String sql = "INSERT INTO cancion(nombre, duracion) VALUES (?,?)"; PreparedStatement preparedStatement; Connection connection = dataSource.getConnection(); connection.setAutoCommit(false); //se obtiene elemento raiz Element cancion = this.xmlDocumento.getRootElement(); //elementos 2do nivel Element nombre = cancion.getChild("nombre"); Element duracion = cancion.getChild("duracion"); Attribute id = cancion.getAttribute("id"); //construye parametros de la query preparedStatement = connection.prepareStatement(sql); preparedStatement.setInt(1, id.getIntValue()); preparedStatement.setString(2, nombre.getText()); preparedStatement.setString(3, duracion.getText()); preparedStatement.execute(); connection.commit(); } catch (Exception e) { //*** se quit el return porque el mtodo es void System.out.println(e.getMessage()); } }
From source file:com.globalsight.ling.tm3.integration.EnableTm3Command.java
@SuppressWarnings("unchecked") @Override//from w w w . j a v a2s. c om protected void handle(CommandLine command) throws Exception { List<String> args = command.getArgList(); if (args.size() != 1) { usage(); } long companyId = 0; try { companyId = Long.valueOf(args.get(0)); } catch (NumberFormatException e) { die("Not a company id: " + args.get(0)); } // Verify it's a valid company. Company company = CompanyWrapper.getCompanyById(companyId); if (company == null) { die("Non-existent company: " + companyId); } Connection conn = DbUtil.getConnection(); conn.setAutoCommit(false); try { new Tm3Enabler(conn, company).enable(this); conn.commit(); } finally { DbUtil.silentReturnConnection(conn); } }
From source file:mayoapp.migrations.V0075_0003__update_tenant_configurations.java
@Override public void migrate(Connection connection) throws Exception { connection.setAutoCommit(false); Statement queryIdsStatement = connection.createStatement(); ResultSet tenants = queryIdsStatement.executeQuery("SELECT entity_id, slug, configuration FROM entity " + "INNER JOIN tenant ON entity.id = tenant.entity_id"); Map<UUID, ConfigurationAndName> tenantsData = Maps.newHashMap(); while (tenants.next()) { String json = tenants.getString("configuration"); String name = tenants.getString("slug"); ObjectMapper objectMapper = new ObjectMapper(); Map<String, Object> configuration = objectMapper.readValue(json, new TypeReference<Map<String, Object>>() { });/*from w w w. j ava2 s . c o m*/ if (configuration.containsKey("general")) { Map<String, Object> generalConfiguration = (Map<String, Object>) configuration.get("general"); if (generalConfiguration.containsKey("name")) { name = (String) generalConfiguration.get("name"); ((Map<String, Object>) configuration.get("general")).remove("name"); json = objectMapper.writeValueAsString(configuration); } } ConfigurationAndName configurationAndName = new ConfigurationAndName(json, name); tenantsData.put((UUID) tenants.getObject("entity_id"), configurationAndName); } queryIdsStatement.close(); PreparedStatement statement = connection .prepareStatement("UPDATE tenant SET name=?, configuration=? WHERE entity_id =?"); for (UUID id : tenantsData.keySet()) { statement.setString(1, tenantsData.get(id).getName()); statement.setString(2, tenantsData.get(id).getConfiguration()); statement.setObject(3, new PG_UUID(id)); statement.addBatch(); } try { statement.executeBatch(); } finally { statement.close(); } }