List of usage examples for java.sql DatabaseMetaData getDatabaseProductName
String getDatabaseProductName() throws SQLException;
From source file:com.bluexml.side.Integration.alfresco.sql.synchronization.schemaManagement.SchemaCreation.java
private void checkMetaData() { logger.debug("Checking meta-data"); DatabaseMetaData dmd = null; Connection connection = DataSourceUtils.getConnection(dataSource); try {/*from ww w . j av a 2 s . c o m*/ dmd = connection.getMetaData(); String dbname = dmd.getDatabaseProductName(); String dbversion = dmd.getDatabaseProductVersion(); if (logger.isDebugEnabled()) logger.debug("Running sql synchronization on " + dbname + " " + dbversion); } catch (SQLException e) { logger.error(e); } finally { DataSourceUtils.releaseConnection(connection, dataSource); } }
From source file:org.apache.ode.scheduler.simple.JdbcDelegate.java
private Dialect guessDialect() { Dialect d = Dialect.UNKNOWN;/*from www. java 2 s . c o m*/ Connection con = null; try { con = getConnection(); DatabaseMetaData metaData = con.getMetaData(); if (metaData != null) { String dbProductName = metaData.getDatabaseProductName(); int dbMajorVer = metaData.getDatabaseMajorVersion(); __log.info("Using database " + dbProductName + " major version " + dbMajorVer); if (dbProductName.indexOf("DB2") >= 0) { d = Dialect.DB2; } else if (dbProductName.indexOf("Derby") >= 0) { d = Dialect.DERBY; } else if (dbProductName.indexOf("Firebird") >= 0) { d = Dialect.FIREBIRD; } else if (dbProductName.indexOf("HSQL") >= 0) { d = Dialect.HSQL; } else if (dbProductName.indexOf("H2") >= 0) { d = Dialect.H2; } else if (dbProductName.indexOf("Microsoft SQL") >= 0) { d = Dialect.SQLSERVER; } else if (dbProductName.indexOf("MySQL") >= 0) { d = Dialect.MYSQL; } else if (dbProductName.indexOf("Sybase") >= 0 || dbProductName.indexOf("Adaptive") >= 0) { d = Dialect.SYBASE; if (dbMajorVer == 12) { d = Dialect.SYBASE12; } } } } catch (SQLException e) { __log.warn("Unable to determine database dialect", e); } finally { close(con); } __log.info("Using database dialect: " + d); return d; }
From source file:org.dspace.storage.rdbms.DatabaseUtils.java
/** * Print basic information about the current database to System.out. * This is utilized by both the 'test' and 'info' commandline options. * @param connection current database connection * @throws SQLException if database error occurs *///from ww w .j a v a2 s . c om private static void printDBInfo(Connection connection) throws SQLException { // Get basic Database info from connection DatabaseMetaData meta = connection.getMetaData(); String dbType = getDbType(connection); System.out.println("\nDatabase Type: " + dbType); System.out.println("Database URL: " + meta.getURL()); System.out.println("Database Schema: " + getSchemaName(connection)); System.out.println("Database Username: " + meta.getUserName()); System.out.println("Database Software: " + meta.getDatabaseProductName() + " version " + meta.getDatabaseProductVersion()); System.out.println("Database Driver: " + meta.getDriverName() + " version " + meta.getDriverVersion()); // For Postgres, report whether pgcrypto is installed // (If it isn't, we'll also write out warnings...see below) if (dbType.equals(DBMS_POSTGRES)) { boolean pgcryptoUpToDate = PostgresUtils.isPgcryptoUpToDate(); Double pgcryptoVersion = PostgresUtils.getPgcryptoInstalledVersion(connection); System.out.println("PostgreSQL '" + PostgresUtils.PGCRYPTO + "' extension installed/up-to-date? " + pgcryptoUpToDate + " " + ((pgcryptoVersion != null) ? "(version=" + pgcryptoVersion + ")" : "(not installed)")); } }
From source file:org.enlacerh.util.Seg002.java
/** * Leer Datos de roles/*from ww w . j a va 2s. c o m*/ * @throws NamingException * @throws IOException **/ public void select(int first, int pageSize, String sortField, Object filterValue) throws SQLException, NamingException, IOException { 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 = ""; switch (productName) { case "Oracle": //Consulta paginada query = " select * from "; query += " ( select query.*, rownum as rn from"; query += " ( SELECT trim(codrol), trim(desrol), trim(grupo)"; query += " FROM SEG002"; query += " where codrol like '" + codrol + "%'"; query += " and codrol||desrol like '%" + ((String) filterValue).toUpperCase() + "%'"; query += " and grupo = '" + grupo + "'"; query += " order by 1) query"; query += " ) where rownum <= " + pageSize; query += " and rn > (" + first + ")"; break; case "PostgreSQL": //Consulta paginada query = "SELECT trim(codrol), trim(desrol), trim(CAST(grupo AS text))"; query += " FROM SEG002"; query += " where codrol like '" + codrol + "%'"; query += " and codrol||desrol like '%" + ((String) filterValue).toUpperCase() + "%'"; query += " and CAST(grupo AS text) = '" + grupo + "'"; 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()) { Rol select = new Rol(); select.setVcodrol(r.getString(1)); select.setVdesrol(r.getString(2)); select.setVgrupo(r.getString(3)); //Agrega la lista list.add(select); rows = list.size(); } //Cierra las conecciones pstmt.close(); con.close(); r.close(); }
From source file:org.openbizview.util.Bvtcat2.java
/** * Leer registros en la tabla//www .j a v a 2 s .c om * @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 (b_codcat1 == null) { b_codcat1 = " - "; } if (b_codcat1 == "") { b_codcat1 = " - "; } String[] veccodcat1 = b_codcat1.split("\\ - ", -1); switch (productName) { case "Oracle": query = "SELECT count_bvtcat2('" + ((String) filterValue).toUpperCase() + "','" + veccodcat1[0] + "','" + instancia + "') from dual"; break; case "PostgreSQL": query = "SELECT count_bvtcat2('" + ((String) filterValue).toUpperCase() + "','" + veccodcat1[0] + "','" + instancia + "')"; break; case "Microsoft SQL Server": query = "SELECT DBO.count_bvtcat2('" + ((String) filterValue).toUpperCase() + "','" + veccodcat1[0] + "','" + instancia + "')"; break; } pstmt = con.prepareStatement(query); //System.out.println(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.Ventas.java
/** * Leer Datos de paises/* w ww . j a v a 2s . com*/ * @throws NamingException * @throws IOException **/ public void select(int first, int pageSize, String sortField, Object filterValue) throws SQLException, ClassNotFoundException, NamingException { if (codven == null) { codven = " - "; } if (codven == "") { codven = " - "; } String[] veccodven = codven.split("\\ - ", -1); //System.out.println("entre al metodo SELECT"); Context initContext = new InitialContext(); DataSource ds = (DataSource) initContext.lookup(JNDISB); 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 * FROM"; query += "(select query.*, query.ROWNUM as rn from"; query += "(SELECT A.CODIGO_VENDEDOR, A.PORC_VISITA, A.ANOCAL, A.MESCAL, count(A.CODIGO_VENDEDOR) AS ROWNUM, B.PERNR + ' - ' + B.NCHMC + ' ' + B.VNAMC CLAVE "; query += " FROM R3P.dbo.TUBDER06 A, R3P.SAPSR3.M_PREMN B"; query += " WHERE LTRIM(RTRIM(A.CODIGO_VENDEDOR)) = LTRIM(RTRIM(B.PERNR))"; query += " AND LTRIM(RTRIM(A.CODIGO_VENDEDOR)) LIKE LTRIM(RTRIM('%" + veccodven[0] + "%'))"; query += " GROUP BY A.CODIGO_VENDEDOR, A.PORC_VISITA, A.ANOCAL, A.MESCAL, B.PERNR, B.NCHMC, B.VNAMC"; query += ")query ) sq1"; query += " WHERE ROWNUM <=" + pageSize; query += " AND rn > (" + first + ")"; query += " ORDER BY " + sortField.replace("z", ""); pstmt = con.prepareStatement(query); //System.out.println(query); r = pstmt.executeQuery(); while (r.next()) { Ventas select = new Ventas(); select.setZcodven(r.getString(1)); select.setZporcvis(r.getString(2)); select.setZanocal(r.getString(3)); select.setZmescal(r.getString(4)); select.setZcoddesc(r.getString(6)); //Agrega la lista list.add(select); } //Cierra las conecciones pstmt.close(); con.close(); }
From source file:org.openbizview.util.Mailgrupos.java
/** * Leer Datos de mailconfig/*ww w.jav a 2 s. com*/ * @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(); productName = databaseMetaData.getDatabaseProductName();//Identifica la base de datos de coneccin String query = ""; switch (productName) { case "Oracle": query += " select * from "; query += " ( select query.*, rownum as rn from"; query += " (SELECT trim(IDGRUPO), trim(DESGRUPO)"; query += " FROM MAILGRUPOS"; query += " WHERE idgrupo||desgrupo like '%" + ((String) filterValue).toUpperCase() + "%'"; query += " and idgrupo like '" + idgrupo + "%'"; query += " AND instancia = '" + instancia + "'"; query += " order by " + sortField + ") query"; query += " ) where rownum <= " + pageSize; query += " and rn > (" + first + ")"; break; case "PostgreSQL": query += " SELECT IDGRUPO, trim(DESGRUPO)"; query += " FROM MAILGRUPOS"; query += " WHERE idgrupo||desgrupo like '%" + ((String) filterValue).toUpperCase() + "%'"; query += " and cast(idgrupo as text) like '" + idgrupo + "%'"; query += " AND instancia = '" + instancia + "'"; query += " order by " + sortField; query += " LIMIT " + pageSize; query += " OFFSET " + first; break; case "Microsoft SQL Server": query += " SELECT TOP " + pageSize; query += " TOT.IDGRUPO, "; query += " TOT.DESGRUPO "; query += " FROM (SELECT "; query += " ROW_NUMBER() OVER (ORDER BY IDGRUPO ASC) AS ROW_NUM, "; query += " IDGRUPO, "; query += " LTRIM(RTRIM(DESGRUPO)) DESGRUPO "; query += " FROM "; query += " MAILGRUPOS) TOT "; query += " WHERE "; query += " LTRIM(RTRIM(CAST(TOT.IDGRUPO AS CHAR))) + TOT.DESGRUPO LIKE '%" + ((String) filterValue).toUpperCase() + "%' "; query += " AND LTRIM(RTRIM(CAST(TOT.IDGRUPO AS CHAR))) LIKE '" + idgrupo + "%' "; query += " AND tot.instancia = '" + instancia + "'"; query += " AND TOT.ROW_NUM > " + first; query += " ORDER BY TOT." + sortField; break; } pstmt = con.prepareStatement(query); //System.out.println(query); r = pstmt.executeQuery(); while (r.next()) { Mailgrupos select = new Mailgrupos(); select.setIdgrupo(r.getString(1)); select.setDesgrupo(r.getString(2)); //Agrega la lista list.add(select); } } catch (SQLException e) { e.printStackTrace(); } //Cierra las conecciones pstmt.close(); con.close(); r.close(); }
From source file:org.enlacerh.util.Seg001.java
/** * Borra Paises/*from w w w . j ava2s . co m*/ * <p> * Parametros del metodo: String codpai. Pool de conecciones **/ public void delete() { HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext() .getRequest(); String[] chkbox = request.getParameterValues("toDelete"); if (chkbox == null) { msj = new FacesMessage(FacesMessage.SEVERITY_WARN, getMessage("pnt003DelPai"), ""); } else { 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 = ""; String param = "'" + StringUtils.join(chkbox, "','") + "'"; switch (productName) { case "Oracle": query = "DELETE FROM SEG001 WHERE grupo in (" + param + ")"; break; case "PostgreSQL": query = "DELETE FROM SEG001 WHERE CAST(grupo AS text) in (" + param + ")"; break; } pstmt = con.prepareStatement(query); //System.out.println(query); //Antes de insertar verifica si el rol del usuario tiene permisos para insertar vGacc = acc.valAccmnu("bas1", "delete", login, JNDI);//LLama a la funcion que valida las opciones del rol if (vGacc) { msj = new FacesMessage(FacesMessage.SEVERITY_ERROR, getMessage("msnAccDelete"), ""); } else { try { //Avisando pstmt.executeUpdate(); if (pstmt.getUpdateCount() <= 1) { msj = new FacesMessage(FacesMessage.SEVERITY_INFO, getMessage("msnDelete"), ""); } else { msj = new FacesMessage(FacesMessage.SEVERITY_INFO, getMessage("msnDeletes"), ""); } limpiarValores(); } catch (SQLException e) { e.printStackTrace(); msj = new FacesMessage(FacesMessage.SEVERITY_FATAL, e.getMessage(), ""); } pstmt.close(); con.close(); } } catch (Exception e) { e.printStackTrace(); } } FacesContext.getCurrentInstance().addMessage(null, msj); }
From source file:org.talend.cwm.db.connection.ConnectionUtils.java
/** * DOC xqliu Comment method "isJdbcIngres". * /*from ww w.j ava 2s. c o m*/ * @param connection * @return * @throws SQLException */ @SuppressWarnings("deprecation") public static boolean isJdbcIngres(java.sql.Connection connection) throws SQLException { DatabaseMetaData connectionMetadata = org.talend.utils.sql.ConnectionUtils .getConnectionMetadata(connection); if (connectionMetadata.getDriverName() != null && connectionMetadata.getDriverName().equals(DatabaseConstant.JDBC_INGRES_DEIVER_NAME) && connectionMetadata.getDatabaseProductName() != null && connectionMetadata.getDatabaseProductName().toLowerCase() .indexOf(DatabaseConstant.INGRES_PRODUCT_NAME) > -1) { return true; } return false; }
From source file:org.enlacerh.util.Pnt003.java
/** * Actualiza Paises//from w ww .j a va 2 s .c o m **/ private void update() { 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 = ""; switch (productName) { case "Oracle": query = "UPDATE PNT003"; query += " SET DESPAI = ?"; query += " , FECACT = '" + getFecha() + "' , USRACT = '" + login + "'"; query += " WHERE codpai = trim('" + codpai + "')"; query += " and grupo = " + Integer.parseInt(localgrupo); break; case "PostgreSQL": query = "UPDATE PNT003"; query += " SET DESPAI = ?"; query += " , FECACT = '" + getFecha() + "' , USRACT = '" + login + "'"; query += " WHERE CAST(codpai AS text) = trim('" + codpai + "')"; query += " and grupo = " + Integer.parseInt(localgrupo); break; } //System.out.println(query); pstmt = con.prepareStatement(query); pstmt.setString(1, despai.toUpperCase()); //Antes de insertar verifica si el rol del usuario tiene permisos para insertar vGacc = acc.valAccmnu("bas01", "update", login, JNDI);//LLama a la funcion que valida las opciones del rol if (vGacc) { msj = new FacesMessage(FacesMessage.SEVERITY_ERROR, getMessage("msnAccUpdate"), ""); } else { try { //Avisando pstmt.executeUpdate(); if (pstmt.getUpdateCount() == 0) { msj = new FacesMessage(FacesMessage.SEVERITY_ERROR, getMessage("msnNoUpdate"), ""); } else { msj = new FacesMessage(FacesMessage.SEVERITY_INFO, getMessage("msnUpdate"), ""); } despai = ""; localgrupo = ""; validarOperacion = 0; } catch (SQLException e) { e.printStackTrace(); msj = new FacesMessage(FacesMessage.SEVERITY_FATAL, e.getMessage(), ""); } pstmt.close(); con.close(); } //Fin validacion de licencia } catch (Exception e) { e.printStackTrace(); } FacesContext.getCurrentInstance().addMessage(null, msj); }