List of usage examples for java.sql DatabaseMetaData getDatabaseProductName
String getDatabaseProductName() throws SQLException;
From source file:org.openbizview.util.Programacion.java
/** * Leer registros en la tabla/*from ww w. j a va 2 s. co m*/ * @throws NamingException * @throws IOException **/ public void counter(Object filterValue) throws SQLException, NamingException { try { Context initContext = new InitialContext(); DataSource ds = (DataSource) initContext.lookup(JNDI); con = ds.getConnection(); //Reconoce la base de datos de coneccin para ejecutar el query correspondiente a cada uno DatabaseMetaData databaseMetaData = con.getMetaData(); productName = databaseMetaData.getDatabaseProductName();//Identifica la base de datos de coneccin String query = ""; if (mailreporteFiltro == null) { mailreporteFiltro = " - "; } if (mailfrecuenciaFiltro == null) { mailfrecuenciaFiltro = " - "; } if (mailgrupoFiltro == null) { mailgrupoFiltro = " - "; } String[] vecrepf = mailreporteFiltro.split("\\ - ", -1); String[] veccfrecf = mailfrecuenciaFiltro.split("\\ - ", -1); String[] vecgrupf = mailgrupoFiltro.split("\\ - ", -1); switch (productName) { case "Oracle": query = "SELECT count_programacion('" + ((String) filterValue).toUpperCase() + "','" + instancia + "','" + vecrepf[0] + "','" + veccfrecf[0] + "','" + vecgrupf[0] + "') from dual"; break; case "PostgreSQL": query = "SELECT count_programacion('" + ((String) filterValue).toUpperCase() + "','" + instancia + "','" + vecrepf[0] + "','" + veccfrecf[0] + "','" + vecgrupf[0] + "')"; break; } //System.out.println(query); pstmt = con.prepareStatement(query); r = pstmt.executeQuery(); while (r.next()) { rows = r.getInt(1); } } catch (SQLException e) { e.printStackTrace(); } //Cierra las conecciones pstmt.close(); con.close(); r.close(); }
From source file:org.openbizview.util.Programacion.java
/** * Inserta Configuracin./*from ww w .j av a 2s. com*/ * Parametros del Metodo: String codpai, String despai. Pool de conecciones y login * @throws NamingException **/ private void delete() throws NamingException { try { Context initContext = new InitialContext(); DataSource ds = (DataSource) initContext.lookup(JNDI); con = ds.getConnection(); //Reconoce la base de datos de coneccin para ejecutar el query correspondiente a cada uno DatabaseMetaData databaseMetaData = con.getMetaData(); String productName = databaseMetaData.getDatabaseProductName();//Identifica la base de datos de coneccin String vlfecha; java.text.SimpleDateFormat sdfecha_es = new java.text.SimpleDateFormat("dd/MM/yyyy HH:mm", locale); java.text.SimpleDateFormat sdfecha_en = new java.text.SimpleDateFormat("dd/MMM/yyyy HH:mm", locale); String to_date; if (OPENBIZVIEW_BD_LANG.equals("es")) { vlfecha = sdfecha_es.format(diainicio); to_date = "to_date('" + vlfecha + "', 'dd/mm/yyyy hh24:mi')"; } else { vlfecha = sdfecha_en.format(diainicio); to_date = "to_date('" + vlfecha + "', 'dd/mon/yyyy hh24:mi')"; } String query = ""; switch (productName) { case "Oracle": query = "DELETE from T_PROGRAMACION WHERE diainicio = " + to_date + " and disparador = '" + vltrigger.toUpperCase() + "' and instancia = '" + instancia + "'"; break; case "PostgreSQL": query = "DELETE from T_PROGRAMACION WHERE diainicio = '" + diainicio + "' and disparador = '" + vltrigger.toUpperCase() + "' and instancia = '" + instancia + "'"; break; } //System.out.println(query); pstmt = con.prepareStatement(query); try { pstmt.executeUpdate(); limpiar(); } catch (SQLException e) { e.printStackTrace(); } pstmt.close(); con.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.sha.util.Programacion.java
/** * Inserta Configuracin.//from www . j ava 2 s .c o m * Parametros del Metodo: String codpai, String despai. Pool de conecciones y login * @throws NamingException **/ private void delete() throws NamingException { try { Context initContext = new InitialContext(); DataSource ds = (DataSource) initContext.lookup(JNDI); con = ds.getConnection(); //Reconoce la base de datos de coneccin para ejecutar el query correspondiente a cada uno DatabaseMetaData databaseMetaData = con.getMetaData(); String productName = databaseMetaData.getDatabaseProductName();//Identifica la base de datos de coneccin String vlfecha; java.text.SimpleDateFormat sdfecha_es = new java.text.SimpleDateFormat("dd/MM/yyyy HH:mm", locale); java.text.SimpleDateFormat sdfecha_en = new java.text.SimpleDateFormat("dd/MMM/yyyy HH:mm", locale); String to_date; if (SHA_BD_LANG.equals("es")) { vlfecha = sdfecha_es.format(diainicio); to_date = "to_date('" + vlfecha + "', 'dd/mm/yyyy hh24:mi')"; } else { vlfecha = sdfecha_en.format(diainicio); to_date = "to_date('" + vlfecha + "', 'dd/mon/yyyy hh24:mi')"; } String query = ""; switch (productName) { case "Oracle": query = "DELETE from T_PROGRAMACION WHERE diainicio = " + to_date + " and disparador = '" + vltrigger.toUpperCase() + "' and instancia = '" + instancia + "'"; break; case "PostgreSQL": query = "DELETE from T_PROGRAMACION WHERE diainicio = '" + diainicio + "' and disparador = '" + vltrigger.toUpperCase() + "' and instancia = '" + instancia + "'"; break; } //System.out.println(query); pstmt = con.prepareStatement(query); try { pstmt.executeUpdate(); limpiar(); } catch (SQLException e) { e.printStackTrace(); } pstmt.close(); con.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.openbizview.util.Programacion.java
/** * Leer Datos dias de la semana//from www . j a va 2s . c o m * @throws SQLException * @throws NamingException * @throws IOException **/ public void selectDiasSemana() { try { Context initContext = new InitialContext(); DataSource ds = (DataSource) initContext.lookup(JNDI); con = ds.getConnection(); //Reconoce la base de datos de coneccin para ejecutar el query correspondiente a cada uno DatabaseMetaData databaseMetaData = con.getMetaData(); String productName = databaseMetaData.getDatabaseProductName();//Identifica la base de datos de coneccin String query = ""; switch (productName) { case "Oracle": query += " SELECT "; query += " case rownum when 1 then 'MON'"; query += " when 2 then 'TUE'"; query += " when 3 then 'WED'"; query += " when 4 then 'THU'"; query += " when 5 then 'FRI'"; query += " when 6 then 'SAT'"; query += " when 7 then 'SUN' end days"; query += " , case rownum when 1 then 'Lunes'"; query += " when 2 then 'Martes'"; query += " when 3 then 'Mircoles'"; query += " when 4 then 'Jueves'"; query += " when 5 then 'Viernes'"; query += " when 6 then 'Sbado'"; query += " when 7 then 'Domingo' end dias"; query += " FROM dual CONNECT BY LEVEL <= 7"; break; case "PostgreSQL": query = "WITH RECURSIVE t(n) AS ("; query += " SELECT 1"; query += " UNION ALL"; query += " SELECT n+1 FROM t"; query += " )"; query += " SELECT case n when 1 then 'MON' when 2 then 'TUE' when 3 then 'WED' when 4 then 'THU' when 5 then 'FRI' when 6 then 'SAT' else 'SUN' end , case n when 1 then 'Lunes' when 2 then 'Martes' when 3 then 'Miercoles' when 4 then 'Jueves' when 5 then 'Viernes' when 6 then 'Sbado' else 'Domingo' end "; query += " FROM t LIMIT 7"; break; } pstmt = con.prepareStatement(query); //System.out.println(query); r = pstmt.executeQuery(); while (r.next()) { Programacion select = new Programacion(); select.setVdiasSemana(r.getString(1)); select.setVdiasSemanaDesc(r.getString(2)); //Agrega la lista list1.add(select); } //Cierra las conecciones pstmt.close(); con.close(); r.close(); } catch (SQLException | SchedulerException | NamingException e) { e.printStackTrace(); } }
From source file:org.openbizview.util.Programacion.java
/** * Inserta Configuracin./* w ww .ja v a 2 s . com*/ * * @throws NamingException **/ private void insert(String pdias, String pdiames, String paramvalues, String intervalo, String paramnames) { try { Context initContext = new InitialContext(); DataSource ds = (DataSource) initContext.lookup(JNDI); con = ds.getConnection(); //Reconoce la base de datos de coneccin para ejecutar el query correspondiente a cada uno DatabaseMetaData databaseMetaData = con.getMetaData(); String productName = databaseMetaData.getDatabaseProductName();//Identifica la base de datos de coneccin String[] vecidgrupo = idgrupo.split("\\ - ", -1); HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext() .getRequest(); String[] chkbox = request.getParameterValues("toDelete"); String param = ""; //System.out.println(param); ////System.out.println("Iniciando tarea diaria"); //Definir la instancia del job if (chkbox == null) { param = ""; } else { param = StringUtils.join(chkbox, ",").replace(" ", ""); } //System.out.println(param); String[] vecreporte = reporte.split("\\ - ", -1); String vlfecha; java.text.SimpleDateFormat sdfecha_es = new java.text.SimpleDateFormat("dd/MM/yyyy HH:mm", locale); java.text.SimpleDateFormat sdfecha_en = new java.text.SimpleDateFormat("dd/MMM/yyyy HH:mm", locale); String to_date; if (OPENBIZVIEW_BD_LANG.equals("es")) { vlfecha = sdfecha_es.format(diainicio); to_date = "to_date('" + vlfecha + "', 'dd/mm/yyyy hh24:mi')"; } else { vlfecha = sdfecha_en.format(diainicio); to_date = "to_date('" + vlfecha + "', 'dd/mon/yyyy hh24:mi')"; } String query = ""; switch (productName) { case "Oracle": query = "INSERT INTO T_PROGRAMACION VALUES (?,?,?,?,?,?,?,?,?,?,?,?," + to_date + ",?,?,?,?,?,?,?,?,?)"; break; case "PostgreSQL": query = "INSERT INTO T_PROGRAMACION VALUES (?,?,?,?,?,?,?,?,?,?,?,?,'" + diainicio + "',?,?,?,?,?,?,?,?,?)"; break; } //System.out.println(query); pstmt = con.prepareStatement(query); pstmt.setString(1, vltrigger.toUpperCase()); pstmt.setString(2, "unico"); pstmt.setInt(3, Integer.parseInt(pdias)); pstmt.setString(4, frecuencia); pstmt.setString(5, asunto); pstmt.setString(6, contenido); pstmt.setString(7, vecreporte[0].toUpperCase()); pstmt.setString(8, BIRT_VIEWER_WORKING_FOLDER); pstmt.setString(9, BIRT_VIEWER_LOG_DIR); pstmt.setInt(10, Integer.parseInt(vecidgrupo[0])); pstmt.setString(11, tarea.toUpperCase()); pstmt.setString(12, pdiames); pstmt.setString(13, "0"); pstmt.setString(14, paramvalues); pstmt.setInt(15, Integer.parseInt(intervalo)); pstmt.setString(16, paramnames); pstmt.setString(17, ruta_salida); pstmt.setString(18, opctareas); pstmt.setString(19, formato); pstmt.setInt(20, Integer.parseInt(instancia)); pstmt.setString(21, param); try { pstmt.executeUpdate(); limpiar(); } catch (SQLException e) { //e.printStackTrace(); msj = new FacesMessage(FacesMessage.SEVERITY_ERROR, e.getMessage(), ""); FacesContext.getCurrentInstance().addMessage(null, msj); } pstmt.close(); con.close(); } catch (Exception e) { //e.printStackTrace(); } }
From source file:org.sha.util.Programacion.java
/** * Inserta Configuracin./*from w w w .j a v a2 s . com*/ * * @throws NamingException **/ private void insert(String pdias, String pdiames, String paramvalues, String intervalo, String paramnames) { try { Context initContext = new InitialContext(); DataSource ds = (DataSource) initContext.lookup(JNDI); con = ds.getConnection(); //Reconoce la base de datos de coneccin para ejecutar el query correspondiente a cada uno DatabaseMetaData databaseMetaData = con.getMetaData(); String productName = databaseMetaData.getDatabaseProductName();//Identifica la base de datos de coneccin String[] vecidgrupo = idgrupo.split("\\ - ", -1); HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext() .getRequest(); String[] chkbox = request.getParameterValues("toDelete"); String param = ""; //System.out.println(param); ////System.out.println("Iniciando tarea diaria"); //Definir la instancia del job if (chkbox == null) { param = ""; } else { param = StringUtils.join(chkbox, ",").replace(" ", ""); } //System.out.println(param); String[] vecreporte = reporte.split("\\ - ", -1); String vlfecha; java.text.SimpleDateFormat sdfecha_es = new java.text.SimpleDateFormat("dd/MM/yyyy HH:mm", locale); java.text.SimpleDateFormat sdfecha_en = new java.text.SimpleDateFormat("dd/MMM/yyyy HH:mm", locale); String to_date; if (SHA_BD_LANG.equals("es")) { vlfecha = sdfecha_es.format(diainicio); to_date = "to_date('" + vlfecha + "', 'dd/mm/yyyy hh24:mi')"; } else { vlfecha = sdfecha_en.format(diainicio); to_date = "to_date('" + vlfecha + "', 'dd/mon/yyyy hh24:mi')"; } String query = ""; switch (productName) { case "Oracle": query = "INSERT INTO T_PROGRAMACION VALUES (?,?,?,?,?,?,?,?,?,?,?,?," + to_date + ",?,?,?,?,?,?,?,?,?)"; break; case "PostgreSQL": query = "INSERT INTO T_PROGRAMACION VALUES (?,?,?,?,?,?,?,?,?,?,?,?,'" + diainicio + "',?,?,?,?,?,?,?,?,?)"; break; } //System.out.println(query); pstmt = con.prepareStatement(query); pstmt.setString(1, vltrigger.toUpperCase()); pstmt.setString(2, "unico"); pstmt.setInt(3, Integer.parseInt(pdias)); pstmt.setString(4, frecuencia); pstmt.setString(5, asunto); pstmt.setString(6, contenido); pstmt.setString(7, vecreporte[0].toUpperCase()); pstmt.setString(8, BIRT_VIEWER_WORKING_FOLDER); pstmt.setString(9, BIRT_VIEWER_LOG_DIR); pstmt.setInt(10, Integer.parseInt(vecidgrupo[0])); pstmt.setString(11, tarea.toUpperCase()); pstmt.setString(12, pdiames); pstmt.setString(13, "0"); pstmt.setString(14, paramvalues); pstmt.setInt(15, Integer.parseInt(intervalo)); pstmt.setString(16, paramnames); pstmt.setString(17, ruta_salida); pstmt.setString(18, opctareas); pstmt.setString(19, formato); pstmt.setInt(20, Integer.parseInt(instancia)); pstmt.setString(21, param); try { pstmt.executeUpdate(); limpiar(); } catch (SQLException e) { //e.printStackTrace(); msj = new FacesMessage(FacesMessage.SEVERITY_ERROR, e.getMessage(), ""); FacesContext.getCurrentInstance().addMessage(null, msj); } pstmt.close(); con.close(); } catch (Exception e) { //e.printStackTrace(); } }
From source file:org.springframework.jdbc.core.metadata.GenericCallMetaDataProvider.java
/** * Process the procedure column metadata *//*from w w w.j a va2s .c o m*/ private void processProcedureColumns(DatabaseMetaData databaseMetaData, @Nullable String catalogName, @Nullable String schemaName, @Nullable String procedureName) { String metaDataCatalogName = metaDataCatalogNameToUse(catalogName); String metaDataSchemaName = metaDataSchemaNameToUse(schemaName); String metaDataProcedureName = procedureNameToUse(procedureName); if (logger.isDebugEnabled()) { logger.debug("Retrieving metadata for " + metaDataCatalogName + '/' + metaDataSchemaName + '/' + metaDataProcedureName); } ResultSet procs = null; try { procs = databaseMetaData.getProcedures(metaDataCatalogName, metaDataSchemaName, metaDataProcedureName); List<String> found = new ArrayList<>(); while (procs.next()) { found.add(procs.getString("PROCEDURE_CAT") + '.' + procs.getString("PROCEDURE_SCHEM") + '.' + procs.getString("PROCEDURE_NAME")); } procs.close(); if (found.size() > 1) { throw new InvalidDataAccessApiUsageException( "Unable to determine the correct call signature - multiple " + "procedures/functions/signatures for '" + metaDataProcedureName + "': found " + found); } else if (found.isEmpty()) { if (metaDataProcedureName != null && metaDataProcedureName.contains(".") && !StringUtils.hasText(metaDataCatalogName)) { String packageName = metaDataProcedureName.substring(0, metaDataProcedureName.indexOf(".")); throw new InvalidDataAccessApiUsageException( "Unable to determine the correct call signature for '" + metaDataProcedureName + "' - package name should be specified separately using '.withCatalogName(\"" + packageName + "\")'"); } else if ("Oracle".equals(databaseMetaData.getDatabaseProductName())) { if (logger.isDebugEnabled()) { logger.debug("Oracle JDBC driver did not return procedure/function/signature for '" + metaDataProcedureName + "' - assuming a non-exposed synonym"); } } else { throw new InvalidDataAccessApiUsageException( "Unable to determine the correct call signature - no " + "procedure/function/signature for '" + metaDataProcedureName + "'"); } } procs = databaseMetaData.getProcedureColumns(metaDataCatalogName, metaDataSchemaName, metaDataProcedureName, null); while (procs.next()) { String columnName = procs.getString("COLUMN_NAME"); int columnType = procs.getInt("COLUMN_TYPE"); if (columnName == null && (columnType == DatabaseMetaData.procedureColumnIn || columnType == DatabaseMetaData.procedureColumnInOut || columnType == DatabaseMetaData.procedureColumnOut)) { if (logger.isDebugEnabled()) { logger.debug("Skipping metadata for: " + columnType + " " + procs.getInt("DATA_TYPE") + " " + procs.getString("TYPE_NAME") + " " + procs.getInt("NULLABLE") + " (probably a member of a collection)"); } } else { CallParameterMetaData meta = new CallParameterMetaData(columnName, columnType, procs.getInt("DATA_TYPE"), procs.getString("TYPE_NAME"), procs.getInt("NULLABLE") == DatabaseMetaData.procedureNullable); this.callParameterMetaData.add(meta); if (logger.isDebugEnabled()) { logger.debug("Retrieved metadata: " + meta.getParameterName() + " " + meta.getParameterType() + " " + meta.getSqlType() + " " + meta.getTypeName() + " " + meta.isNullable()); } } } } catch (SQLException ex) { if (logger.isWarnEnabled()) { logger.warn("Error while retrieving metadata for procedure columns: " + ex); } } finally { try { if (procs != null) { procs.close(); } } catch (SQLException ex) { if (logger.isWarnEnabled()) { logger.warn("Problem closing ResultSet for procedure column metadata: " + ex); } } } }
From source file:mondrian.test.loader.MondrianFoodMartLoader.java
/** * Load output from the input, optionally creating tables, * populating tables and creating indexes */// ww w. j ava2 s . c o m private void load() throws Exception { if (!StringUtils.isBlank(jdbcDrivers)) { RolapUtil.loadDrivers(jdbcDrivers); } if (userName == null) { connection = DriverManager.getConnection(jdbcURL); } else { connection = DriverManager.getConnection(jdbcURL, userName, password); } if (jdbcInput) { if (inputUserName == null) { inputConnection = DriverManager.getConnection(inputJdbcURL); } else { inputConnection = DriverManager.getConnection(inputJdbcURL, inputUserName, inputPassword); } } final DatabaseMetaData metaData = connection.getMetaData(); String productName = metaData.getDatabaseProductName(); String version = metaData.getDatabaseProductVersion(); LOGGER.info("Output connection is " + productName + ", version: " + version); dialect = DialectManager.createDialect(null, connection); LOGGER.info( "Mondrian Dialect is " + dialect + ", detected database product: " + dialect.getDatabaseProduct()); if (dialect.getDatabaseProduct() == Dialect.DatabaseProduct.INFOBRIGHT && indexes) { System.out.println("Infobright engine detected: ignoring indexes"); indexes = false; } if (outputBatchSize == -1) { // No explicit batch size was set by user, so assign a good // default now if (dialect.getDatabaseProduct() == Dialect.DatabaseProduct.LUCIDDB) { // LucidDB column-store writes perform better with large batches outputBatchSize = 1000; } else { outputBatchSize = 50; } } if (dialect.getDatabaseProduct() == Dialect.DatabaseProduct.LUCIDDB) { // LucidDB doesn't support CREATE UNIQUE INDEX, but it // does support standard UNIQUE constraints generateUniqueConstraints = true; } try { final Condition<String> tableFilter; if (include != null || exclude != null) { tableFilter = new Condition<String>() { public boolean test(String tableName) { if (include != null) { if (!include.matcher(tableName).matches()) { return false; } } if (exclude != null) { if (!exclude.matcher(tableName).matches()) { return true; } } // Table name matched the inclusion criterion // (or everything was included) // and did not match the exclusion criterion // (or nothing was excluded), // therefore is included. return true; } }; } else { tableFilter = new Condition<String>() { public boolean test(String s) { return true; } }; } if (generateUniqueConstraints) { // Initialize tableConstraints createIndexes(false, false, tableFilter); } // This also initializes tableMetadataToLoad createTables(tableFilter); if (data) { if (!populationQueries) { if (jdbcInput) { loadDataFromJdbcInput(tableFilter, pauseMillis, outputBatchSize); } else { loadDataFromFile(tableFilter, pauseMillis, outputBatchSize); } } // Index the base tables before running queries to populate // the summary tables. if (indexes) { createIndexes(true, false, tableFilter); } loadFromSqlInserts(); } else { // Create indexes without loading data. if (indexes) { createIndexes(true, false, tableFilter); } } if (indexes && aggregates) { createIndexes(false, true, tableFilter); } if (analyze) { analyzeTables(); } } finally { if (connection != null) { connection.close(); connection = null; } if (inputConnection != null) { inputConnection.close(); inputConnection = null; } if (fileOutput != null) { fileOutput.close(); fileOutput = null; } } }
From source file:org.openbizview.util.Programacion.java
/**Actualiza job existente * Elimina y vuelve a crear/*from w w w. java 2s .com*/ * @throws NamingException */ public void updateExistingJob() throws NamingException { //Vuelve a crear la tarea if (ruta_salida == null) { ruta_salida = ""; } String[] vecreporte = reporte.split("\\ - ", -1); String[] vecidgrupo = idgrupo.split("\\ - ", -1); //Elimina lo existente try { //schd.unscheduleJob(triggerKey(vltrigger.toUpperCase(), "unico")); schd.deleteJob(jobKey(vltrigger.toUpperCase(), "unico"));//Reimplementacin, anteriormente solo la quitaba de la tarea no la borraba //Nuevo cambio 20/09/2014 //System.out.println("Detiene a: " + vltrigger.toUpperCase()); //Modifica los valores Context initContext = new InitialContext(); DataSource ds = (DataSource) initContext.lookup(JNDI); con = ds.getConnection(); //Reconoce la base de datos de coneccin para ejecutar el query correspondiente a cada uno DatabaseMetaData databaseMetaData = con.getMetaData(); String productName = databaseMetaData.getDatabaseProductName();//Identifica la base de datos de coneccin arregloParametros = StringUtils.join(inputs, "|").toUpperCase(); String vlfecha; java.text.SimpleDateFormat sdfecha_es = new java.text.SimpleDateFormat("dd/MM/yyyy HH:mm", locale); java.text.SimpleDateFormat sdfecha_en = new java.text.SimpleDateFormat("dd/MMM/yyyy HH:mm", locale); String to_date; if (OPENBIZVIEW_BD_LANG.equals("es")) { vlfecha = sdfecha_es.format(diainicio); to_date = "to_date('" + vlfecha + "', 'dd/mm/yyyy hh24:mi')"; } else { vlfecha = sdfecha_en.format(diainicio); to_date = "to_date('" + vlfecha + "', 'dd/mon/yyyy hh24:mi')"; } String query = ""; switch (productName) { case "Oracle": query = "UPDATE t_programacion"; query += " SET diasem = '" + dias + "'"; query += " , frecuencia = '" + frecuencia + "'"; query += " , asunto = '" + asunto + "'"; query += " , contenido = '" + contenido + "'"; query += " , codrep = '" + vecreporte[0].toUpperCase() + "'"; query += " , idgrupo = '" + Integer.parseInt(vecidgrupo[0]) + "'"; query += " , diames = '" + diames + "'"; query += " , diainicio = " + to_date; query += " , paramvalues = '" + arregloParametros + "'"; query += " , intervalo = '" + horarepeticion + "'"; query += " , paramnames = '" + arregloParamNames(vecreporte[0]) + "'"; query += " , ruta_salida = '" + ruta_salida + "'"; query += " , opctareas = '" + opctareas + "'"; query += " , formato = '" + formato + "'"; query += " WHERE disparador = '" + vltrigger.toUpperCase() + "'"; query += " AND instancia = '" + instancia + "'"; break; case "PostgreSQL": query = "UPDATE t_programacion"; query += " SET diasem = '" + dias + "'"; query += " , frecuencia = '" + frecuencia + "'"; query += " , asunto = '" + asunto + "'"; query += " , contenido = '" + contenido + "'"; query += " , codrep = '" + vecreporte[0].toUpperCase() + "'"; query += " , idgrupo = '" + Integer.parseInt(vecidgrupo[0]) + "'"; query += " , diames = '" + diames + "'"; query += " , diainicio = '" + diainicio + "'"; query += " , paramvalues = '" + arregloParametros + "'"; query += " , intervalo = '" + horarepeticion + "'"; query += " , paramnames = '" + arregloParamNames(vecreporte[0]) + "'"; query += " , ruta_salida = '" + ruta_salida + "'"; query += " , opctareas = '" + opctareas + "'"; query += " , formato = '" + formato + "'"; query += " WHERE disparador = '" + vltrigger.toUpperCase() + "'"; query += " AND instancia = '" + instancia + "'"; break; } // System.out.println(query); pstmt = con.prepareStatement(query); // Antes de ejecutar valida si existe el registro en la base de Datos. pstmt.executeUpdate(); //Cierra conecciones pstmt.close(); con.close(); } catch (SchedulerException | SQLException e) { e.printStackTrace(); msj = new FacesMessage(FacesMessage.SEVERITY_ERROR, e.getMessage(), ""); FacesContext.getCurrentInstance().addMessage(null, msj); } //Creamos la instancia calendario para separar en dia, mes y ao la fecha seleccionada Calendar cal = Calendar.getInstance(); cal.setTime(diainicio); int hora = cal.get(Calendar.HOUR_OF_DAY); int minutos = cal.get(Calendar.MINUTE); //Para iniciar meses comenzando desde enero = 0 //Incia tarea if (frecuencia.equals("0")) { iniciarTareaDiaria(tarea.toUpperCase(), vltrigger.toUpperCase(), arregloParametros, "1", arregloParamNames(vecreporte[0]), hora, minutos); } else if (frecuencia.equals("1")) { iniciarTareaSemanal(tarea.toUpperCase(), vltrigger.toUpperCase(), dias, arregloParametros, "1", arregloParamNames(vecreporte[0]), hora, minutos); } else if (frecuencia.equals("2")) { iniciarTareaDiaMes(tarea.toUpperCase(), vltrigger.toUpperCase(), diames, arregloParametros, "1", arregloParamNames(vecreporte[0]), hora, minutos); } else if (frecuencia.equals("3")) { iniciarTareaIntervaloMinutos(tarea.toUpperCase(), vltrigger.toUpperCase(), horarepeticion, arregloParametros, "1", arregloParamNames(vecreporte[0])); } else if (frecuencia.equals("4")) { iniciarTareaIntervaloMensual(tarea.toUpperCase(), vltrigger.toUpperCase(), arregloParametros, "1", arregloParamNames(vecreporte[0])); } else { iniciarTareaRepeticion(tarea.toUpperCase(), vltrigger.toUpperCase(), arregloParametros, "1", arregloParamNames(vecreporte[0]), "0", hora, minutos); } //System.out.println("fin"); }
From source file:org.sha.util.Programacion.java
/**Actualiza job existente * Elimina y vuelve a crear/*from w w w.j a v a2s. c om*/ * @throws NamingException */ public void updateExistingJob() throws NamingException { //Vuelve a crear la tarea if (ruta_salida == null) { ruta_salida = ""; } String[] vecreporte = reporte.split("\\ - ", -1); String[] vecidgrupo = idgrupo.split("\\ - ", -1); //Elimina lo existente try { //schd.unscheduleJob(triggerKey(vltrigger.toUpperCase(), "unico")); schd.deleteJob(jobKey(vltrigger.toUpperCase(), "unico"));//Reimplementacin, anteriormente solo la quitaba de la tarea no la borraba //Nuevo cambio 20/09/2014 //System.out.println("Detiene a: " + vltrigger.toUpperCase()); //Modifica los valores Context initContext = new InitialContext(); DataSource ds = (DataSource) initContext.lookup(JNDI); con = ds.getConnection(); //Reconoce la base de datos de coneccin para ejecutar el query correspondiente a cada uno DatabaseMetaData databaseMetaData = con.getMetaData(); String productName = databaseMetaData.getDatabaseProductName();//Identifica la base de datos de coneccin arregloParametros = StringUtils.join(inputs, "|").toUpperCase(); String vlfecha; java.text.SimpleDateFormat sdfecha_es = new java.text.SimpleDateFormat("dd/MM/yyyy HH:mm", locale); java.text.SimpleDateFormat sdfecha_en = new java.text.SimpleDateFormat("dd/MMM/yyyy HH:mm", locale); String to_date; if (SHA_BD_LANG.equals("es")) { vlfecha = sdfecha_es.format(diainicio); to_date = "to_date('" + vlfecha + "', 'dd/mm/yyyy hh24:mi')"; } else { vlfecha = sdfecha_en.format(diainicio); to_date = "to_date('" + vlfecha + "', 'dd/mon/yyyy hh24:mi')"; } String query = ""; switch (productName) { case "Oracle": query = "UPDATE t_programacion"; query += " SET diasem = '" + dias + "'"; query += " , frecuencia = '" + frecuencia + "'"; query += " , asunto = '" + asunto + "'"; query += " , contenido = '" + contenido + "'"; query += " , codrep = '" + vecreporte[0].toUpperCase() + "'"; query += " , idgrupo = '" + Integer.parseInt(vecidgrupo[0]) + "'"; query += " , diames = '" + diames + "'"; query += " , diainicio = " + to_date; query += " , paramvalues = '" + arregloParametros + "'"; query += " , intervalo = '" + horarepeticion + "'"; query += " , paramnames = '" + arregloParamNames(vecreporte[0]) + "'"; query += " , ruta_salida = '" + ruta_salida + "'"; query += " , opctareas = '" + opctareas + "'"; query += " , formato = '" + formato + "'"; query += " WHERE disparador = '" + vltrigger.toUpperCase() + "'"; query += " AND instancia = '" + instancia + "'"; break; case "PostgreSQL": query = "UPDATE t_programacion"; query += " SET diasem = '" + dias + "'"; query += " , frecuencia = '" + frecuencia + "'"; query += " , asunto = '" + asunto + "'"; query += " , contenido = '" + contenido + "'"; query += " , codrep = '" + vecreporte[0].toUpperCase() + "'"; query += " , idgrupo = '" + Integer.parseInt(vecidgrupo[0]) + "'"; query += " , diames = '" + diames + "'"; query += " , diainicio = '" + diainicio + "'"; query += " , paramvalues = '" + arregloParametros + "'"; query += " , intervalo = '" + horarepeticion + "'"; query += " , paramnames = '" + arregloParamNames(vecreporte[0]) + "'"; query += " , ruta_salida = '" + ruta_salida + "'"; query += " , opctareas = '" + opctareas + "'"; query += " , formato = '" + formato + "'"; query += " WHERE disparador = '" + vltrigger.toUpperCase() + "'"; query += " AND instancia = '" + instancia + "'"; break; } // System.out.println(query); pstmt = con.prepareStatement(query); // Antes de ejecutar valida si existe el registro en la base de Datos. pstmt.executeUpdate(); //Cierra conecciones pstmt.close(); con.close(); } catch (SchedulerException | SQLException e) { e.printStackTrace(); msj = new FacesMessage(FacesMessage.SEVERITY_ERROR, e.getMessage(), ""); FacesContext.getCurrentInstance().addMessage(null, msj); } //Creamos la instancia calendario para separar en dia, mes y ao la fecha seleccionada Calendar cal = Calendar.getInstance(); cal.setTime(diainicio); int hora = cal.get(Calendar.HOUR_OF_DAY); int minutos = cal.get(Calendar.MINUTE); //Para iniciar meses comenzando desde enero = 0 //Incia tarea if (frecuencia.equals("0")) { iniciarTareaDiaria(tarea.toUpperCase(), vltrigger.toUpperCase(), arregloParametros, "1", arregloParamNames(vecreporte[0]), hora, minutos); } else if (frecuencia.equals("1")) { iniciarTareaSemanal(tarea.toUpperCase(), vltrigger.toUpperCase(), dias, arregloParametros, "1", arregloParamNames(vecreporte[0]), hora, minutos); } else if (frecuencia.equals("2")) { iniciarTareaDiaMes(tarea.toUpperCase(), vltrigger.toUpperCase(), diames, arregloParametros, "1", arregloParamNames(vecreporte[0]), hora, minutos); } else if (frecuencia.equals("3")) { iniciarTareaIntervaloMinutos(tarea.toUpperCase(), vltrigger.toUpperCase(), horarepeticion, arregloParametros, "1", arregloParamNames(vecreporte[0])); } else if (frecuencia.equals("4")) { iniciarTareaIntervaloMensual(tarea.toUpperCase(), vltrigger.toUpperCase(), arregloParametros, "1", arregloParamNames(vecreporte[0])); } else { iniciarTareaRepeticion(tarea.toUpperCase(), vltrigger.toUpperCase(), arregloParametros, "1", arregloParamNames(vecreporte[0]), "0", hora, minutos); } //System.out.println("fin"); }