List of usage examples for java.sql DatabaseMetaData getDatabaseProductName
String getDatabaseProductName() throws SQLException;
From source file:org.openbizview.util.Programacion.java
/** * Leer Datos de mailconfig//from w ww . j a v a 2 s . c om * @throws NamingException * @throws IOException **/ public void select(int first, int pageSize, String sortField, 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(); String productName = databaseMetaData.getDatabaseProductName();//Identifica la base de datos de coneccin String query = ""; if (opctareas == null) { opctareas = "1"; } 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 * from "; query += " ( select query.*, rownum as rn from"; query += " ( select trim(a.job), trim(a.disparador), case a.frecuencia when '0' then '" + getMessage("mailtareaDiario").toUpperCase() + "' when '1' then '" + getMessage("mailtareaSemanal").toUpperCase() + "' when '2' then'" + getMessage("mailtareaPersonalizada").toUpperCase() + "' when '3' then '" + getMessage("mailtareaHoraRep").toUpperCase() + "' when '4' then '" + getMessage("mailimes1").toUpperCase() + "' when '5' then '" + getMessage("maillidiasSelect").toUpperCase() + "' else '" + getMessage("maillidiasSelect1").toUpperCase() + "' end , a.diasem"; query += " , trim(a.codrep), trim(a.idgrupo), trim(a.asunto), trim(a.contenido), trim(b.desgrupo) , trim(a.frecuencia), trim(a.diames), trim(to_char(a.diainicio, 'dd/mm/yyyy HH24:mi')), decode(trim(activa),'0','chkActiva','chkInactiva'), trim(activa), decode(trim(activa),'0','" + getMessage("mailtarea0") + "','" + getMessage("mailtarea1") + "'), trim(a.formato)"; query += " , case when activa = '0' then 'fa fa-circle fa-2x text-success' else 'fa fa-circle fa-2x text-danger' end, trim(paramvalues), intervalo"; query += " from t_programacion a, mailgrupos b"; query += " where a.idgrupo=b.idgrupo"; query += " and A.instancia=B.instancia"; query += " and a.job||a.codrep like '%" + ((String) filterValue).toUpperCase() + "%'"; query += " and a.codrep like '" + vecrepf[0] + "%'"; query += " and a.frecuencia like '" + veccfrecf[0] + "%'"; query += " and a.idgrupo like '" + vecgrupf[0] + "%'"; query += " AND a.instancia = '" + instancia + "'"; query += " order by " + sortField.replace("v", "") + ") query"; query += " ) where rownum <= " + pageSize; query += " and rn > (" + first + ")"; break; case "PostgreSQL": query = "select trim(a.job), trim(a.disparador), case a.frecuencia when '0' then '" + getMessage("mailtareaDiario").toUpperCase() + "' when '1' then '" + getMessage("mailtareaSemanal").toUpperCase() + "' when '2' then'" + getMessage("mailtareaPersonalizada").toUpperCase() + "' when '3' then '" + getMessage("mailtareaHoraRep").toUpperCase() + "' when '4' then '" + getMessage("mailimes1").toUpperCase() + "' when '5' then '" + getMessage("maillidiasSelect").toUpperCase() + "' else '" + getMessage("maillidiasSelect1").toUpperCase() + "' end , a.diasem"; query += " , trim(a.codrep), trim(cast(a.idgrupo as text)), trim(a.asunto), trim(a.contenido), trim(b.desgrupo) , trim(a.frecuencia), trim(a.diames), trim(to_char(a.diainicio, 'dd/mm/yyyy hh24:mi')), case when trim(activa) = '0' then 'chkActiva' else 'chkInactiva' end, trim(activa), case when trim(activa) = '0' then '" + getMessage("mailtarea0") + "' else '" + getMessage("mailtarea1") + "' end, trim(a.formato)"; query += " , case when activa = '0' then 'fa fa-circle fa-2x text-success' else 'fa fa-circle fa-2x text-danger' end, trim(paramvalues), intervalo"; query += " from t_programacion a, mailgrupos b"; query += " where a.idgrupo=b.idgrupo"; query += " and A.instancia=B.instancia"; query += " and a.job||a.codrep like '%" + ((String) filterValue).toUpperCase() + "%'"; query += " and a.codrep like '" + vecrepf[0] + "%'"; query += " and a.frecuencia like '" + veccfrecf[0] + "%'"; query += " and cast(a.idgrupo as text) like '" + vecgrupf[0] + "%'"; query += " and a.disparador like '" + vltrigger + "%'"; query += " AND a.instancia = '" + instancia + "'"; query += " order by " + sortField.replace("v", ""); query += " LIMIT " + pageSize; query += " OFFSET " + first; break; } pstmt = con.prepareStatement(query); //System.out.println(query); r = pstmt.executeQuery(); while (r.next()) { Programacion select = new Programacion(); select.setVjob(r.getString(1)); select.setVdisparador(r.getString(2)); select.setVfrecuenciades(r.getString(3)); select.setVdiasem(r.getString(4)); select.setVcodrep(r.getString(5)); select.setVidgrupo(r.getString(6)); select.setVasunto(r.getString(7)); select.setVcontenido(r.getString(8)); select.setViddesidgrupo(r.getString(9)); select.setVfrecuencia(r.getString(10)); select.setVdiames(r.getString(11)); select.setVdiainicio(r.getString(12)); select.setClase(r.getString(13)); select.setActiva(r.getString(14)); select.setVactivadetalletb(r.getString(15)); select.setVformato(r.getString(16).toUpperCase()); select.setStatusIncon(r.getString(17)); select.setVparamvalues(r.getString(18)); select.setVintervalo(r.getString(19)); //Agrega la lista list.add(select); rows = list.size(); } } catch (SQLException | SchedulerException e) { e.printStackTrace(); } //Cierra las conecciones pstmt.close(); con.close(); r.close(); }
From source file:org.openbizview.util.Sgc001.java
public void guardarti() throws NamingException, SQLException { if (comp == null) { comp = " - "; }/*from w w w . j a v a2 s . c o m*/ if (comp == "") { comp = " - "; } if (area == null) { area = " - "; } if (area == "") { area = " - "; } if (codigo == null) { codigo = " - "; } if (codigo == "") { codigo = " - "; } String[] veccomp = comp.split("\\ - ", -1); String[] vecarea = area.split("\\ - ", -1); String[] veccod = codigo.split("\\ - ", -1); //////System.out.println("entre al metodo SELECT"); 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 //Consulta paginada String query = "SELECT A.TIPVAL, A.TOLINF, TRIM(TO_CHAR(A.FECCAM,'DD/MM/YYYY')) AS FECCAM, E.DESCR AS DESC4, F.DESCR AS DESC5, J.DESCR AS DESC6, A.REGIST "; query += " FROM SGC001B A, SGC005 E, SGC006 F, TUBDER11 J, (SELECT MAX(A.REGIST) AS REGIST "; query += " FROM SGC001B A "; query += " WHERE TRIM(A.COMP) LIKE TRIM('%" + veccomp[0] + "%') "; query += " AND TRIM(A.AREA) LIKE TRIM('%" + vecarea[0] + "%') "; query += " AND TRIM(A.CODIGO) LIKE TRIM('%" + veccod[0] + "%')) SQ1 "; query += " WHERE A.COMP = E.CODIGO"; query += " AND A.AREA = F.CODIGO"; query += " AND A.TIPVAL = J.CODIGO"; query += " AND TRIM(A.COMP) LIKE TRIM('%" + veccomp[0] + "%')"; query += " AND TRIM(A.AREA) LIKE TRIM('%" + vecarea[0] + "%')"; query += " AND TRIM(A.CODIGO) LIKE TRIM('%" + veccod[0] + "%')"; query += " AND A.REGIST = SQ1.REGIST"; query += " GROUP BY A.TIPVAL, A.TOLINF, A.FECCAM, E.DESCR, F.DESCR, J.DESCR, A.REGIST"; query += " ORDER BY 7"; pstmt = con.prepareStatement(query); //////System.out.println(query); r = pstmt.executeQuery(); while (r.next()) { Sgc001 select = new Sgc001(); select.setZtvalti(r.getString(1) + " - " + r.getString(6)); select.setZtolinf(r.getString(2)); select.setZfeccai(r.getString(3)); //////System.out.println(r.getString(1)); if ((tolinf + tvalti + sdfecha3.format(feccai)) .equals(r.getString(2) + r.getString(1) + " - " + r.getString(6) + r.getString(3))) { ////System.out.println(tolinf+tvalti+sdfecha3.format(feccai)); ////System.out.println(r.getString(2)+r.getString(1)+ " - " + r.getString(6)+r.getString(3)); ////System.out.println("no hago el insert tolinf, los valores son iguales"); } else { ////System.out.println(tolinf+tvalti+sdfecha3.format(feccai)); ////System.out.println(r.getString(2)+r.getString(1)+ " - " + r.getString(6)+r.getString(3)); ////System.out.println("hago el insert tolinf, los valores son diferentes"); insertti(); } } //Cierra las conecciones pstmt.close(); con.close(); guardarts(); }
From source file:org.openbizview.util.Sgc001.java
public void guardarts() throws NamingException, SQLException { if (comp == null) { comp = " - "; }/* www. j a va 2 s. co m*/ if (comp == "") { comp = " - "; } if (area == null) { area = " - "; } if (area == "") { area = " - "; } if (codigo == null) { codigo = " - "; } if (codigo == "") { codigo = " - "; } String[] veccomp = comp.split("\\ - ", -1); String[] vecarea = area.split("\\ - ", -1); String[] veccod = codigo.split("\\ - ", -1); //////System.out.println("entre al metodo SELECT"); 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 //Consulta paginada String query = "SELECT A.TIPVAL, A.TOLSUP, TRIM(TO_CHAR(A.FECCAM,'DD/MM/YYYY')) AS FECCAM, E.DESCR AS DESC4, F.DESCR AS DESC5, J.DESCR AS DESC6, A.REGIST "; query += " FROM SGC001C A, SGC005 E, SGC006 F, TUBDER11 J, (SELECT MAX(A.REGIST) AS REGIST "; query += " FROM SGC001C A "; query += " WHERE TRIM(A.COMP) LIKE TRIM('%" + veccomp[0] + "%') "; query += " AND TRIM(A.AREA) LIKE TRIM('%" + vecarea[0] + "%') "; query += " AND TRIM(A.CODIGO) LIKE TRIM('%" + veccod[0] + "%')) SQ1 "; query += " WHERE A.COMP = E.CODIGO"; query += " AND A.AREA = F.CODIGO"; query += " AND A.TIPVAL = J.CODIGO"; query += " AND TRIM(A.COMP) LIKE TRIM('%" + veccomp[0] + "%')"; query += " AND TRIM(A.AREA) LIKE TRIM('%" + vecarea[0] + "%')"; query += " AND TRIM(A.CODIGO) LIKE TRIM('%" + veccod[0] + "%')"; query += " AND A.REGIST = SQ1.REGIST"; query += " GROUP BY A.TIPVAL, A.TOLSUP, A.FECCAM, E.DESCR, F.DESCR, J.DESCR, A.REGIST"; query += " ORDER BY 7"; pstmt = con.prepareStatement(query); //////System.out.println(query); r = pstmt.executeQuery(); while (r.next()) { Sgc001 select = new Sgc001(); select.setZtvalts(r.getString(1) + " - " + r.getString(6)); select.setZtolsup(r.getString(2)); select.setZfeccas(r.getString(3)); //////System.out.println(r.getString(1)); if ((tolsup + tvalts + sdfecha3.format(feccas)) .equals(r.getString(2) + r.getString(1) + " - " + r.getString(6) + r.getString(3))) { ////System.out.println(tolsup+tvalts+sdfecha3.format(feccas)); ////System.out.println(r.getString(2)+r.getString(1)+ " - " + r.getString(6)+r.getString(3)); ////System.out.println("no hago el insert tolsup, los valores son iguales"); limpiarValores(); ////System.out.println("Limpio Valores"); } else { ////System.out.println(tolsup+tvalts+sdfecha3.format(feccas)); ////System.out.println(r.getString(2)+r.getString(1)+ " - " + r.getString(6)+r.getString(3)); ////System.out.println("hago el insert tolsup, los valores son diferentes"); insertts(); limpiarValores(); ////System.out.println("Limpio Valores"); } } //Cierra las conecciones pstmt.close(); con.close(); //limpiarValores(); if (exito == "exito") { msj = new FacesMessage(FacesMessage.SEVERITY_INFO, getMessage("msnUpdate"), ""); FacesContext.getCurrentInstance().addMessage(null, msj); } }
From source file:org.openbizview.util.Sgc001.java
public void guardar() throws NamingException, SQLException { if (validarOperacion == 0) { insert();/*from ww w. j a v a2 s.co m*/ //inserth(); insertm(); insertti(); insertts(); if (exito == "exito") { limpiarValores(); msj = new FacesMessage(FacesMessage.SEVERITY_INFO, getMessage("msnInsert"), ""); FacesContext.getCurrentInstance().addMessage(null, msj); } } else { update(); if (comp == null) { comp = " - "; } if (comp == "") { comp = " - "; } if (area == null) { area = " - "; } if (area == "") { area = " - "; } if (codigo == null) { codigo = " - "; } if (codigo == "") { codigo = " - "; } String[] veccomp = comp.split("\\ - ", -1); String[] vecarea = area.split("\\ - ", -1); String[] veccod = codigo.split("\\ - ", -1); //////System.out.println("entre al metodo SELECT"); 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 //Consulta paginada String query = "SELECT A.TIPVAL, A.META, TRIM(TO_CHAR(A.FECCAM,'DD/MM/YYYY')) AS FECCAM, E.DESCR AS DESC4, F.DESCR AS DESC5, J.DESCR AS DESC6, TRIM(A.RESMET) AS RESMET, A.REGIST "; query += " FROM SGC001A A, SGC005 E, SGC006 F, TUBDER11 J, (SELECT MAX(A.REGIST) AS REGIST "; query += " FROM SGC001A A "; query += " WHERE TRIM(A.COMP) LIKE TRIM('%" + veccomp[0] + "%') "; query += " AND TRIM(A.AREA) LIKE TRIM('%" + vecarea[0] + "%') "; query += " AND TRIM(A.CODIGO) LIKE TRIM('%" + veccod[0] + "%')) SQ1 "; query += " WHERE A.COMP = E.CODIGO"; query += " AND A.AREA = F.CODIGO"; query += " AND A.TIPVAL = J.CODIGO"; query += " AND TRIM(A.COMP) LIKE TRIM('%" + veccomp[0] + "%')"; query += " AND TRIM(A.AREA) LIKE TRIM('%" + vecarea[0] + "%')"; query += " AND TRIM(A.CODIGO) LIKE TRIM('%" + veccod[0] + "%')"; query += " AND A.REGIST = SQ1.REGIST"; query += " GROUP BY A.TIPVAL, A.META, A.FECCAM, E.DESCR, F.DESCR, J.DESCR, A.RESMET, A.REGIST"; query += " ORDER BY 8"; pstmt = con.prepareStatement(query); //////System.out.println(query); r = pstmt.executeQuery(); while (r.next()) { Sgc001 select = new Sgc001(); select.setZtvalm(r.getString(1) + " - " + r.getString(6)); select.setZmeta(r.getString(2)); select.setZfeccam(r.getString(3)); select.setZresmet(r.getString(7)); //////System.out.println(r.getString(1)); if ((meta + tvalm + sdfecha3.format(feccam) + resmet).equals(r.getString(2) + r.getString(1) + " - " + r.getString(6) + r.getString(3) + r.getString(7))) { ////System.out.println(meta+tvalm+sdfecha3.format(feccam)+resmet); ////System.out.println(r.getString(2)+r.getString(1)+ " - " + r.getString(6)+r.getString(3)+r.getString(7)); ////System.out.println("no hago el insert meta, los valores son iguales"); } else { ////System.out.println(meta+tvalm+sdfecha3.format(feccam)+resmet); ////System.out.println(r.getString(2)+r.getString(1)+ " - " + r.getString(6)+r.getString(3)+r.getString(7)); ////System.out.println("hago el insert meta, los valores son diferentes"); insertm(); } } //Cierra las conecciones pstmt.close(); con.close(); guardarh(); } }
From source file:org.openbizview.util.Sgc001.java
public void guardarh() throws NamingException, SQLException { //////System.out.println("entre al metodo guardarh"); if (comp == null) { comp = " - "; }//from w ww . ja v a 2 s.c om if (comp == "") { comp = " - "; } if (area == null) { area = " - "; } if (area == "") { area = " - "; } if (codigo == null) { codigo = " - "; } if (codigo == "") { codigo = " - "; } String[] veccomp = comp.split("\\ - ", -1); String[] vecarea = area.split("\\ - ", -1); String[] veccod = codigo.split("\\ - ", -1); //////System.out.println("entre al metodo SELECT"); 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 //Consulta paginada String query = "SELECT A.CODIGO, A.NOMIND, A.CALCULO, A.DATOS, A.PROCES, A.PERIOD, A.NIVAPP, A.DESCRI, A.ESTATU, TO_CHAR(A.VIGENC,'DD/MM/YYYY') AS VIGENC, B.DESCR AS DESC1, C.DESCR AS DESC2, D.DESCR AS DESC3, A.COMP, A.AREA, E.DESCR AS DESC4, F.DESCR AS DESC5, A.COMPOR, A.REGIST "; query += " FROM SGC001D A, TUBDER08 B, TUBDER10 C, TUBDER09 D, SGC005 E, SGC006 F, (SELECT MAX(A.REGIST) AS REGIST "; query += " FROM SGC001D A "; query += " WHERE TRIM(A.COMP) LIKE TRIM('%" + veccomp[0] + "%') "; query += " AND TRIM(A.AREA) LIKE TRIM('%" + vecarea[0] + "%') "; query += " AND TRIM(A.CODIGO) LIKE TRIM('%" + veccod[0] + "%')) SQ1 "; query += " WHERE A.PERIOD = D.CODIGO"; query += " AND A.NIVAPP = B.CODIGO"; query += " AND A.ESTATU = C.CODIGO"; query += " AND A.COMP = E.CODIGO"; query += " AND A.AREA = F.CODIGO"; query += " AND A.REGIST = SQ1.REGIST"; query += " GROUP BY A.CODIGO, A.NOMIND, A.CALCULO, A.DATOS, A.PROCES, A.PERIOD, A.NIVAPP, A.DESCRI, A.ESTATU, A.VIGENC, B.DESCR, C.DESCR, D.DESCR, A.COMP, A.AREA, E.DESCR, F.DESCR, A.COMPOR, A.REGIST"; query += " ORDER BY 19"; pstmt = con.prepareStatement(query); //////System.out.println(query); //////System.out.println(veccomp[0]); //////System.out.println(vecarea[0]); //////System.out.println(codigo); //////System.out.println(desc); //////System.out.println(calcul); //////System.out.println(fuente); //////System.out.println(proces); //////System.out.println(vecperiod[0]); //////System.out.println(vecnivapp[0]); //////System.out.println(respon.toUpperCase()); //////System.out.println(vecestatu[0]); //////System.out.println(sdfecha.format(vigenc)); //////System.out.println(compor); r = pstmt.executeQuery(); while (r.next()) { Sgc001 select = new Sgc001(); select.setZcodigo(r.getString(1)); select.setZdesc(r.getString(2)); select.setZcalcul(r.getString(3)); select.setZfuente(r.getString(4)); select.setZproces(r.getString(5)); select.setZperiod(r.getString(6) + " - " + r.getString(13)); select.setZnivapp(r.getString(7) + " - " + r.getString(11)); select.setZrespon(r.getString(8)); select.setZestatu(r.getString(9) + " - " + r.getString(12)); select.setZvigenc(r.getString(10)); select.setZdesc1(r.getString(11)); select.setZdesc2(r.getString(12)); select.setZdesc3(r.getString(13)); select.setZcomp(r.getString(14) + " - " + r.getString(16)); select.setZarea(r.getString(15) + " - " + r.getString(17)); select.setZcompor(r.getString(18)); //////System.out.println(r.getString(1)); if ((comp + area + codigo + desc + calcul + fuente + proces + period + nivapp + respon + estatu + sdfecha3.format(vigenc) + compor) .equals(r.getString(14) + " - " + r.getString(16) + r.getString(15) + " - " + r.getString(17) + r.getString(1) + r.getString(2) + r.getString(3) + r.getString(4) + r.getString(5) + r.getString(6) + " - " + r.getString(13) + r.getString(7) + " - " + r.getString(11) + r.getString(8) + r.getString(9) + " - " + r.getString(12) + r.getString(10) + r.getString(18))) { //////System.out.println(comp+area+codigo+desc+calcul+fuente+proces+period+nivapp+respon+estatu+sdfecha3.format(vigenc)+compor); //////System.out.println(r.getString(14) + " - " + r.getString(16)+r.getString(15) + " - " + r.getString(17)+r.getString(1)+r.getString(2)+r.getString(3)+r.getString(4)+r.getString(5)+r.getString(6) + " - " + r.getString(13)+r.getString(7) + " - " + r.getString(11)+r.getString(8)+r.getString(9) + " - " + r.getString(12)+r.getString(10)+r.getString(18)); //////System.out.println("no hago el insert historico, los valores son iguales"); } else { //////System.out.println(comp+area+codigo+desc+calcul+fuente+proces+period+nivapp+respon+estatu+sdfecha3.format(vigenc)+compor); //////System.out.println(r.getString(14) + " - " + r.getString(16)+r.getString(15) + " - " + r.getString(17)+r.getString(1)+r.getString(2)+r.getString(3)+r.getString(4)+r.getString(5)+r.getString(6) + " - " + r.getString(13)+r.getString(7) + " - " + r.getString(11)+r.getString(8)+r.getString(9) + " - " + r.getString(12)+r.getString(10)+r.getString(18)); //////System.out.println("hago el insert historico, los valores son diferentes"); inserth(); } } //Cierra las conecciones pstmt.close(); con.close(); guardarti(); }
From source file:org.talend.metadata.managment.model.DBConnectionFillerImpl.java
@Override public DatabaseConnection fillUIConnParams(IMetadataConnection metadataBean, DatabaseConnection connection) { DatabaseConnection newConnection = null; if (connection == null) { newConnection = ConnectionFactory.eINSTANCE.createDatabaseConnection(); }//from ww w . j a va 2s. co m if (super.fillUIConnParams(metadataBean, newConnection == null ? connection : newConnection) == null) { return null; } DatabaseConnection dbconn = null; if (newConnection != null) { dbconn = newConnection; } else { dbconn = connection; } if (newConnection != null && dbconn != null) { dbconn.setDriverJarPath(metadataBean.getDriverJarPath()); dbconn.setProductId(metadataBean.getProduct()); dbconn.setDbmsId(metadataBean.getMapping()); dbconn.setAdditionalParams(metadataBean.getAdditionalParams()); dbconn.setDriverClass(metadataBean.getDriverClass()); dbconn.setDatabaseType(metadataBean.getDbType()); dbconn.setName(metadataBean.getLabel()); dbconn.setLabel(metadataBean.getLabel()); dbconn.setVersion(metadataBean.getVersion()); // MOD klliu bug 21074 2011-05-19 dbconn.setUiSchema(metadataBean.getUiSchema()); dbconn.setSQLMode(metadataBean.isSqlMode()); dbconn.setSID(metadataBean.getDatabase()); // MOD copy parameter from metadata to dbconn for (Map.Entry<String, Object> parameter : metadataBean.getOtherParameters().entrySet()) { dbconn.getParameters().put(parameter.getKey(), parameter.getValue() == null ? StringUtils.EMPTY : parameter.getValue().toString()); } } java.sql.Connection sqlConnection = null; try { sqlConnection = MetadataConnectionUtils.createConnection(metadataBean).getObject(); // MetadataConnectionUtils.setMetadataCon(metadataBean); // fill some base parameter if (newConnection != null) { fillMetadataParams(metadataBean, newConnection); } DatabaseMetaData dbMetadata = null; // Added by Marvin Wang on Mar. 13, 2013 for loading hive jars dynamically, refer to TDI-25072. if (EDatabaseTypeName.HIVE.getXmlName().equalsIgnoreCase(metadataBean.getDbType())) { dbMetadata = HiveConnectionManager.getInstance().extractDatabaseMetaData(metadataBean); } else { // software dbMetadata = ExtractMetaDataUtils.getInstance().getDatabaseMetaData(sqlConnection, dbconn, false); } if (dbMetadata != null) { // MOD sizhaoliu TDQ-6316 The 2 tagged values should be added for all database including Hive String productName = dbMetadata.getDatabaseProductName() == null ? PluginConstant.EMPTY_STRING : dbMetadata.getDatabaseProductName(); String productVersion = dbMetadata.getDatabaseProductVersion() == null ? PluginConstant.EMPTY_STRING : dbMetadata.getDatabaseProductVersion(); TaggedValueHelper.setTaggedValue(dbconn, TaggedValueHelper.DB_PRODUCT_NAME, productName); TaggedValueHelper.setTaggedValue(dbconn, TaggedValueHelper.DB_PRODUCT_VERSION, productVersion); boolean isHive = dbconn.getDatabaseType().equals(EDatabaseTypeName.HIVE.getDisplayName()); boolean isHiveJdbc = dbconn.getDatabaseType() .equals(EDatabaseTypeName.GENERAL_JDBC.getDisplayName()) && dbconn.getDriverClass() != null && dbconn.getDriverClass().equals(EDatabase4DriverClassName.HIVE.getDriverClass()); boolean isImpala = dbconn.getDatabaseType().equals(EDatabaseTypeName.IMPALA.getDisplayName()); boolean isImpalaJdbc = dbconn.getDatabaseType().equals(EDatabaseTypeName.IMPALA.getDisplayName()) && dbconn.getDriverClass() != null && dbconn.getDriverClass().equals(EDatabase4DriverClassName.IMPALA.getDriverClass()); if (!isHive && !isHiveJdbc && !isImpala && !isImpalaJdbc) { String identifierQuote = dbMetadata.getIdentifierQuoteString(); ConnectionHelper.setIdentifierQuoteString(identifierQuote == null ? "" : identifierQuote, //$NON-NLS-1$ dbconn); } } } catch (SQLException e) { log.error(e, e); } catch (ClassNotFoundException e) { CommonExceptionHandler.process(e); } catch (InstantiationException e) { CommonExceptionHandler.process(e); } catch (IllegalAccessException e) { CommonExceptionHandler.process(e); } finally { if (sqlConnection != null) { ConnectionUtils.closeConnection(sqlConnection); } if (driver != null && MetadataConnectionUtils.isDerbyRelatedDb(metadataBean.getDriverClass(), metadataBean.getDbType())) { try { driver.connect("jdbc:derby:;shutdown=true", null); //$NON-NLS-1$ } catch (SQLException e) { // exception of shutdown success. no need to catch. } } } if (newConnection != null) { return newConnection; } else { return connection; } }
From source file:org.openbizview.util.Sgc001.java
/** * Leer Datos de paises//from w w w . ja v a 2s. c o m * @throws NamingException * @throws IOException **/ public void select(int first, int pageSize, String sortField, Object filterValue) throws SQLException, ClassNotFoundException, NamingException { 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 validar = "1"; String querycon = "SELECT BI_SGC014('" + login.toUpperCase() + "') AS VALIDAR FROM DUAL"; //////System.out.println(querycon); //////System.out.println(JNDI); consulta.selectPntGenerica(querycon, JNDI); rows = consulta.getRows(); tabla = consulta.getArray(); //////System.out.println(tabla[0][0]); if (tabla[0][0].equals(validar)) { if (comp == null) { comp = " - "; } if (comp == "") { comp = " - "; } if (area == null) { area = " - "; } if (area == "") { area = " - "; } String[] veccomp = comp.split("\\ - ", -1); String[] vecarea = area.split("\\ - ", -1); //Consulta paginada String query = "SELECT * FROM"; query += "(select query.*, rownum as rn from"; query += "(SELECT A.CODIGO, A.NOMIND, A.TIPVALM, A.META, TO_CHAR(A.FECCAM,'DD/MM/YYYY') AS FECCAM, A.TIPVALTI, A.TOLINF, TO_CHAR(A.FECCATI,'DD/MM/YYYY') AS FECCATI, A.TIPVALTS, A.TOLSUP, TO_CHAR(A.FECCATS,'DD/MM/YYYY') AS FECCATS, A.CALCULO, A.DATOS, A.PROCES, A.PERIOD, A.NIVAPP, A.DESCRI, A.ESTATU, TO_CHAR(A.VIGENC,'DD/MM/YYYY') AS VIGENC, B.DESCR AS DESC1, C.DESCR AS DESC2, D.DESCR AS DESC3, A.COMP, A.AREA, E.DESCR AS DESC4, F.DESCR AS DESC5, J.DESCR AS DESC6, A.COMPOR, A.RESMET "; query += " FROM SGC001 A, TUBDER08 B, TUBDER10 C, TUBDER09 D, SGC005 E, SGC006 F, TUBDER11 J, TUBDER11 K, TUBDER11 L "; query += " WHERE A.PERIOD = D.CODIGO"; query += " AND A.NIVAPP = B.CODIGO"; query += " AND A.ESTATU = C.CODIGO"; query += " AND A.COMP = E.CODIGO"; query += " AND A.AREA = F.CODIGO"; query += " AND A.TIPVALM = J.CODIGO"; query += " AND A.TIPVALTI = K.CODIGO"; query += " AND A.TIPVALTS = L.CODIGO"; query += " AND TRIM(A.COMP) LIKE TRIM('%" + veccomp[0] + "%')"; query += " AND TRIM(A.AREA) LIKE TRIM('%" + vecarea[0] + "%')"; query += " AND TRIM(A.CODIGO)||TRIM(A.NOMIND) LIKE TRIM('%" + ((String) filterValue).toUpperCase() + "%')"; query += " GROUP BY A.CODIGO, A.NOMIND, A.TIPVALM, A.META, A.FECCAM, A.TIPVALTI, A.TOLINF, A.FECCATI, A.TIPVALTS, A.TOLSUP, A.FECCATS, A.CALCULO, A.DATOS, A.PROCES, A.PERIOD, A.NIVAPP, A.DESCRI, A.ESTATU, A.VIGENC, B.DESCR, C.DESCR, D.DESCR, A.COMP, A.AREA, E.DESCR, F.DESCR, J.DESCR, A.COMPOR, A.RESMET"; query += " ORDER BY A.COMP, A.AREA, A.CODIGO "; query += ")query ) "; query += " WHERE ROWNUM <=" + pageSize; query += " AND rn > (" + first + ")"; pstmt = con.prepareStatement(query); ////System.out.println(query); ////System.out.println("Usuario ADMINISTRADOR..."); r = pstmt.executeQuery(); while (r.next()) { Sgc001 select = new Sgc001(); select.setZcodigo(r.getString(1)); select.setZdesc(r.getString(2)); select.setZtvalm(r.getString(3) + " - " + r.getString(27)); select.setZmeta(r.getString(4)); select.setZfeccam(r.getString(5)); select.setZtvalti(r.getString(6) + " - " + r.getString(27)); select.setZtolinf(r.getString(7)); select.setZfeccai(r.getString(8)); select.setZtvalts(r.getString(9) + " - " + r.getString(27)); select.setZtolsup(r.getString(10)); select.setZfeccas(r.getString(11)); select.setZcalcul(r.getString(12)); select.setZfuente(r.getString(13)); select.setZproces(r.getString(14)); select.setZperiod(r.getString(15) + " - " + r.getString(22)); select.setZnivapp(r.getString(16) + " - " + r.getString(20)); select.setZrespon(r.getString(17)); select.setZestatu(r.getString(18) + " - " + r.getString(21)); select.setZvigenc(r.getString(19)); select.setZdesc1(r.getString(20)); select.setZdesc2(r.getString(21)); select.setZdesc3(r.getString(22)); select.setZcomp(r.getString(23) + " - " + r.getString(25)); select.setZarea(r.getString(24) + " - " + r.getString(26)); select.setZdesc4(r.getString(27)); select.setZdelete(r.getString(23) + "" + r.getString(24) + "" + r.getString(1)); select.setZcompor(r.getString(28)); select.setZresmet(r.getString(29)); //select.setZobvtoli(r.getString(30) + " - " + r.getString(31)); //select.setZobvtols(r.getString(32) + " - " + r.getString(33)); //Agrega la lista list.add(select); } //Cierra las conecciones pstmt.close(); con.close(); } else { if (comp == null) { comp = " - "; } if (comp == "") { comp = " - "; } if (area == null) { area = " - "; } if (area == "") { area = " - "; } String[] veccomp = comp.split("\\ - ", -1); String[] vecarea = area.split("\\ - ", -1); String query = " SELECT"; query += " TOT.*, rownum as rn"; query += " FROM (select"; query += " DISTINCT"; query += " REV.CODIGO, REV.NOMIND, REV.TIPVALM, REV.META, REV.FECCAM, REV.TIPVALTI, REV.TOLINF, REV.FECCATI, REV.TIPVALTS, REV.TOLSUP, REV.FECCATS, REV.CALCULO, REV.DATOS, REV.PROCES, REV.PERIOD,"; query += " REV.NIVAPP, REV.DESCRI, REV.ESTATU, REV.VIGENC, REV.DESC1, REV.DESC2, REV.DESC3, REV.COMP, REV.AREA, REV.DESC4, REV.DESC5, REV.DESC6, REV.COMPOR, REV.RESMET "; query += " from (SELECT"; query += " A.COMP, A.AREA, A.CODIGO, A.NOMIND, A.TIPVALM, A.META, TO_CHAR(A.FECCAM,'DD/MM/YYYY') FECCAM, A.TIPVALTI, A.TOLINF, TO_CHAR(A.FECCATI,'DD/MM/YYYY') FECCATI, A.TIPVALTS, A.TOLSUP,"; query += " TO_CHAR(A.FECCATS,'DD/MM/YYYY') FECCATS, A.CALCULO, A.DATOS, A.PROCES, A.PERIOD, A.NIVAPP, A.DESCRI, A.ESTATU, TO_CHAR(A.VIGENC,'DD/MM/YYYY') VIGENC, B.DESCR DESC1,"; query += " C.DESCR DESC2, D.DESCR DESC3, E.DESCR DESC4, F.DESCR DESC5, J.DESCR DESC6, A.COMPOR, A.RESMET, A.OBVTOLI, DECODE(A.OBVTOLI,'1','SI','NO') SINOTI, A.OBVTOLS, DECODE(A.OBVTOLS,'1','SI','NO') SINOTS "; query += " FROM"; query += " SGC001 A, TUBDER08 B, TUBDER10 C, TUBDER09 D, SGC005 E, SGC006 F, TUBDER11 J, TUBDER11 K, TUBDER11 L, SGC009 M"; query += " WHERE"; query += " A.PERIOD = D.CODIGO"; query += " AND A.NIVAPP = B.CODIGO"; query += " AND A.ESTATU = C.CODIGO "; query += " AND A.COMP = E.CODIGO"; query += " AND A.AREA = F.CODIGO"; query += " AND A.TIPVALM = J.CODIGO"; query += " AND A.TIPVALTI = K.CODIGO"; query += " AND A.TIPVALTS = L.CODIGO"; query += " AND A.COMP = M.COMP"; query += " AND A.AREA = M.AREA"; query += " AND A.CODIGO = M.INDICA"; query += " AND TRIM(M.CODUSER) LIKE ('%" + login.toUpperCase() + "%')"; query += " AND TRIM(A.CODIGO)||TRIM(A.NOMIND) LIKE TRIM('%" + ((String) filterValue).toUpperCase() + "%')"; query += " GROUP BY A.CODIGO, A.NOMIND, A.TIPVALM, A.META, A.FECCAM, A.TIPVALTI, A.TOLINF, A.FECCATI, A.TIPVALTS, A.TOLSUP, A.FECCATS, A.CALCULO, A.DATOS,"; query += " A.PROCES, A.PERIOD, A.NIVAPP, A.DESCRI, A.ESTATU, A.VIGENC, B.DESCR, C.DESCR, D.DESCR, A.COMP, A.AREA, E.DESCR, F.DESCR, J.DESCR, A.COMPOR, A.RESMET, A.OBVTOLI, A.OBVTOLS "; query += " UNION ALL"; query += " SELECT"; query += " A.COMP, A.AREA, A.CODIGO, A.NOMIND, A.TIPVALM, A.META, TO_CHAR(A.FECCAM,'DD/MM/YYYY') FECCAM, A.TIPVALTI, A.TOLINF, TO_CHAR(A.FECCATI,'DD/MM/YYYY') FECCATI, A.TIPVALTS, A.TOLSUP,"; query += " TO_CHAR(A.FECCATS,'DD/MM/YYYY') FECCATS, A.CALCULO, A.DATOS, A.PROCES, A.PERIOD, A.NIVAPP, A.DESCRI, A.ESTATU, TO_CHAR(A.VIGENC,'DD/MM/YYYY') VIGENC, B.DESCR DESC1,"; query += " C.DESCR DESC2, D.DESCR DESC3, E.DESCR DESC4, F.DESCR DESC5, J.DESCR DESC6, A.COMPOR, A.RESMET, A.OBVTOLI, DECODE(A.OBVTOLI,'1','SI','NO') SINOTI, A.OBVTOLS, DECODE(A.OBVTOLS,'1','SI','NO') SINOTS "; query += " FROM "; query += " SGC001 A, TUBDER08 B, TUBDER10 C, TUBDER09 D, SGC005 E, SGC006 F, TUBDER11 J, TUBDER11 K, TUBDER11 L"; query += " WHERE "; query += " A.PERIOD = D.CODIGO "; query += " AND A.NIVAPP = B.CODIGO "; query += " AND A.ESTATU = C.CODIGO "; query += " AND A.COMP = E.CODIGO "; query += " AND A.AREA = F.CODIGO "; query += " AND A.TIPVALM = J.CODIGO "; query += " AND A.TIPVALTI = K.CODIGO "; query += " AND A.TIPVALTS = L.CODIGO "; query += " AND A.COMP||A.AREA IN (SELECT COMP||AREA FROM SGC008 WHERE CODUSER = '" + login.toUpperCase() + "' AND DUEPRO = '1')"; query += " AND TRIM(A.CODIGO)||TRIM(A.NOMIND) LIKE TRIM('%" + ((String) filterValue).toUpperCase() + "%')"; query += " GROUP BY A.CODIGO, A.NOMIND, A.TIPVALM, A.META, A.FECCAM, A.TIPVALTI, A.TOLINF, A.FECCATI, A.TIPVALTS, A.TOLSUP, A.FECCATS, A.CALCULO, A.DATOS, "; query += " A.PROCES, A.PERIOD, A.NIVAPP, A.DESCRI, A.ESTATU, A.VIGENC, B.DESCR, C.DESCR, D.DESCR, A.COMP, A.AREA, E.DESCR, F.DESCR, J.DESCR, A.COMPOR, A.RESMET, A.OBVTOLI, A.OBVTOLS) REV"; query += " WHERE"; query += " TRIM(REV.COMP) LIKE TRIM('%" + veccomp[0] + "%')"; query += " AND TRIM(REV.AREA) LIKE TRIM('%" + vecarea[0] + "%')"; query += " ORDER BY REV.COMP, REV.AREA, REV.CODIGO) TOT"; query += " WHERE ROWNUM <=15 AND ROWNUM > (0) ORDER BY TOT.COMP, TOT.AREA, TOT.CODIGO "; pstmt = con.prepareStatement(query); //System.out.println(query); ////System.out.println("Usuario **** NO **** ADMINISTRADOR..."); r = pstmt.executeQuery(); while (r.next()) { Sgc001 select = new Sgc001(); select.setZcodigo(r.getString(1)); select.setZdesc(r.getString(2)); select.setZtvalm(r.getString(3) + " - " + r.getString(27)); select.setZmeta(r.getString(4)); select.setZfeccam(r.getString(5)); select.setZtvalti(r.getString(6) + " - " + r.getString(27)); select.setZtolinf(r.getString(7)); select.setZfeccai(r.getString(8)); select.setZtvalts(r.getString(9) + " - " + r.getString(27)); select.setZtolsup(r.getString(10)); select.setZfeccas(r.getString(11)); select.setZcalcul(r.getString(12)); select.setZfuente(r.getString(13)); select.setZproces(r.getString(14)); select.setZperiod(r.getString(15) + " - " + r.getString(22)); select.setZnivapp(r.getString(16) + " - " + r.getString(20)); select.setZrespon(r.getString(17)); select.setZestatu(r.getString(18) + " - " + r.getString(21)); select.setZvigenc(r.getString(19)); select.setZdesc1(r.getString(20)); select.setZdesc2(r.getString(21)); select.setZdesc3(r.getString(22)); select.setZcomp(r.getString(23) + " - " + r.getString(25)); select.setZarea(r.getString(24) + " - " + r.getString(26)); select.setZdesc4(r.getString(27)); select.setZdelete(r.getString(23) + "" + r.getString(24) + "" + r.getString(1)); select.setZcompor(r.getString(28)); select.setZresmet(r.getString(29)); //select.setZobvtoli(r.getString(30) + " - " + r.getString(31)); //select.setZobvtols(r.getString(32) + " - " + r.getString(33)); //Agrega la lista list.add(select); } //Cierra las conecciones pstmt.close(); con.close(); } }
From source file:swp.bibjsf.persistence.Data.java
/** * Returns the lower-case names of all tables in the database. * * @return list of lower-case names of all tables in the database * @throws SQLException// www . j a v a 2s .c o m * falls ein Fehler beim Zugriff auf die Datenbank auftritt */ private List<String> getTableNames() throws SQLException { logger.debug("get table names"); DatabaseMetaData dbMeta; List<String> result = new ArrayList<String>(); Connection dbConnection = dataSource.getConnection(); try { dbMeta = dbConnection.getMetaData(); logger.debug("URL of database " + dbMeta.getURL()); logger.debug("database version: major=" + dbMeta.getDatabaseMajorVersion() + " minor=" + dbMeta.getDatabaseMinorVersion() + " product_version=" + dbMeta.getDatabaseProductVersion() + " product_name=" + dbMeta.getDatabaseProductName()); ResultSet rs = dbMeta.getTables(null, null, null, new String[] { "TABLE" }); try { while (rs.next()) { String theTableName = rs.getString("TABLE_NAME"); result.add(theTableName.toLowerCase()); } } finally { rs.close(); } return result; } finally { try { dbConnection.close(); } catch (SQLException e) { logger.debug("error while trying to close the database connection."); // ignore, nothing to be done here anyway } } }
From source file:org.kawanfw.sql.servlet.DatabaseMetaDataExecutor.java
/** * //from ww w . j ava2 s. c om * Calls a remote metadata method from the PC <br> * * @throws IOException * all network, etc. errors * @throws ClassNotFoundException * @throws IllegalAccessException * @throws InstantiationException * @throws NoSuchMethodException * @throws SecurityException * @throws InvocationTargetException * @throws IllegalArgumentException */ private void callMetaDataFunction(HttpServletRequest request, OutputStream out, Connection connection) throws SQLException, IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, IllegalArgumentException, InvocationTargetException { // The method name String methodName = request.getParameter(Parameter.METHOD_NAME); // methodName = HtmlConverter.fromHtml(methodName); // The parms name String paramsTypes = request.getParameter(Parameter.PARAMS_TYPES); String paramsValues = request.getParameter(Parameter.PARAMS_VALUES); // Make sure all values are not null and trimed methodName = this.getTrimValue(methodName); paramsTypes = this.getTrimValue(paramsTypes); paramsValues = this.getTrimValue(paramsValues); debug("actionInvokeRemoteMethod:methodName : " + methodName); // paramsTypes = HtmlConverter.fromHtml(paramsTypes); // paramsValues = HtmlConverter.fromHtml(paramsValues); List<String> listParamsTypes = ListOfStringTransport.fromJson(paramsTypes); List<String> listParamsValues = ListOfStringTransport.fromJson(paramsValues); debug("actionInvokeRemoteMethod:listParamsTypes : " + listParamsTypes); debug("actionInvokeRemoteMethod:listParamsValues : " + listParamsValues); DatabaseMetaData databaseMetaData = connection.getMetaData(); // Trap DatabaseMetaData.getTables() & DatabaseMetaData.getUDTs() // that have special array String[] or int[] parameters if (methodName.equals("getTables") || methodName.equals("getUDTs") || methodName.equals("getPrimaryKeys")) { DatabaseMetaDataSpecial databaseMetaDataSpecial = new DatabaseMetaDataSpecial(databaseMetaData, methodName, listParamsValues); ResultSet rs = databaseMetaDataSpecial.execute(); dumpResultSetOnServletOutStream(rs); return; } @SuppressWarnings("rawtypes") Class[] argTypes = new Class[listParamsTypes.size()]; Object[] values = new Object[listParamsValues.size()]; for (int i = 0; i < listParamsTypes.size(); i++) { String value = listParamsValues.get(i); String javaType = listParamsTypes.get(i); JavaValueBuilder javaValueBuilder = new JavaValueBuilder(javaType, value); argTypes[i] = javaValueBuilder.getClassOfValue(); values[i] = javaValueBuilder.getValue(); // Trap NULL values if (values[i].equals("NULL")) { values[i] = null; } debug("argTypes[i]: " + argTypes[i]); debug("values[i] : " + values[i]); } Class<?> c = Class.forName("java.sql.DatabaseMetaData"); Object theObject = databaseMetaData; // Invoke the method Method main = null; Object resultObj = null; // Get the Drvier Info String database = ""; String productVersion = ""; String DriverName = ""; String DriverVersion = ""; String driverInfo = Tag.PRODUCT; // try { // database = databaseMetaData.getDatabaseProductName(); // productVersion = databaseMetaData.getDatabaseProductVersion(); // DriverName = databaseMetaData.getDriverName(); // DriverVersion= databaseMetaData.getDriverVersion(); // driverInfo += database + " " + productVersion + " " + DriverName + // " " + DriverVersion; // } catch (Exception e1) { // ServerLogger.getLogger().log(Level.WARNING, Tag.PRODUCT + // "Impossible to get User Driver info."); // } database = databaseMetaData.getDatabaseProductName(); productVersion = databaseMetaData.getDatabaseProductVersion(); DriverName = databaseMetaData.getDriverName(); DriverVersion = databaseMetaData.getDriverVersion(); driverInfo += database + " " + productVersion + " " + DriverName + " " + DriverVersion; String methodParams = getMethodParams(values); try { main = c.getDeclaredMethod(methodName, argTypes); } catch (SecurityException e) { throw new SecurityException(driverInfo + " - Security - Impossible to get declared DatabaseMetaData." + methodName + "(" + methodParams + ")"); } catch (NoSuchMethodException e) { throw new NoSuchMethodException( driverInfo + " - No Such Method - Impossible get declared DatabaseMetaData." + methodName + "(" + methodParams + ")"); } try { resultObj = main.invoke(theObject, values); } catch (IllegalArgumentException e) { throw new IllegalArgumentException( driverInfo + " - Impossible to call DatabaseMetaData." + methodName + "(" + methodParams + ")"); } catch (IllegalAccessException e) { throw new IllegalAccessException(driverInfo + " - Impossible to access DatabaseMetaData method." + methodName + "(" + methodParams + ")"); } catch (InvocationTargetException e) { throw new InvocationTargetException(e, driverInfo + " - Impossible to invoke DatabaseMetaData method." + methodName + "(" + methodParams + ")"); } if (resultObj instanceof ResultSet) { ResultSet rs = (ResultSet) resultObj; dumpResultSetOnServletOutStream(rs); } else { // All other formats are handled in String String result = null; if (resultObj != null) result = resultObj.toString(); debug("actionInvokeRemoteMethod:result: " + result); result = HtmlConverter.toHtml(result); //out.println(TransferStatus.SEND_OK); //out.println(result); ServerSqlManager.writeLine(out, TransferStatus.SEND_OK); ServerSqlManager.writeLine(out, result); } }
From source file:org.talend.core.model.metadata.builder.database.ExtractMetaDataUtils.java
/** * DOC cantoine. Method to return DatabaseMetaData of a DB connection. * /* www . jav a 2 s . c o m*/ * @param Connection conn * @param isSqlMode whether is sqlMode * @param String dbType * @return DatabaseMetaData * * */ public DatabaseMetaData getDatabaseMetaData(Connection conn, String dbType, boolean isSqlMode, String database) { DatabaseMetaData dbMetaData = null; try { if (conn != null && !conn.isClosed()) { // MOD sizhaoliu 2012-5-21 TDQ-4884 if (MSSQL_CONN_CLASS.equals(conn.getClass().getName())) { dbMetaData = createJtdsDatabaseMetaData(conn); } else if (EDatabaseTypeName.IBMDB2ZOS.getXmlName().equals(dbType)) { dbMetaData = createDB2ForZosFakeDatabaseMetaData(conn); } else if (EDatabaseTypeName.TERADATA.getXmlName().equals(dbType) && isSqlMode) { dbMetaData = createTeradataFakeDatabaseMetaData(conn); // add by wzhang for bug 8106. set database name for teradata. TeradataDataBaseMetadata teraDbmeta = (TeradataDataBaseMetadata) dbMetaData; teraDbmeta.setDatabaseName(database); } else if (EDatabaseTypeName.SAS.getXmlName().equals(dbType)) { dbMetaData = createSASFakeDatabaseMetaData(conn); } else if (EDatabaseTypeName.SYBASEASE.getDisplayName().equals(dbType) || SYBASE_DATABASE_PRODUCT_NAME.equals(dbType)) { // TDQ-8300 make sybaseIQ work well,currently,the dbType of sybaseIQ is still // "Sybase (ASE and IQ)",so use dbMetaData.getDatabaseProductName() to judge if it is sybaseIQ . dbMetaData = conn.getMetaData(); if (dbMetaData != null && EDatabaseTypeName.SYBASEIQ.getDisplayName() .equals(dbMetaData.getDatabaseProductName())) { dbMetaData = createSybaseIQFakeDatabaseMetaData(conn); } else { dbMetaData = createSybaseFakeDatabaseMetaData(conn); } } else if (EDatabaseTypeName.HIVE.getDisplayName().equals(dbType) && isHiveEmbeddedConn(conn)) { // dbMetaData = new EmbeddedHiveDataBaseMetadata(conn); } else if (EDatabaseTypeName.AS400.getXmlName().equals(dbType)) { dbMetaData = createAS400FakeDatabaseMetaData(conn); } else { dbMetaData = conn.getMetaData(); } } } catch (SQLException e) { log.error(e.toString()); throw new RuntimeException(e); } catch (Exception e) { log.error(e.toString()); throw new RuntimeException(e); } return dbMetaData; }