Example usage for java.sql DatabaseMetaData getDatabaseProductName

List of usage examples for java.sql DatabaseMetaData getDatabaseProductName

Introduction

In this page you can find the example usage for java.sql DatabaseMetaData getDatabaseProductName.

Prototype

String getDatabaseProductName() throws SQLException;

Source Link

Document

Retrieves the name of this database product.

Usage

From source file:org.enlacerh.util.Seg007.java

/**
  * Leer Datos de compaas para asignar a menucheck
  * @throws NamingException //from   w ww.j  a va 2s  .  co m
 * @throws SQLException 
  * @throws IOException 
  **/
private void selectSeg007Cias() throws NamingException, SQLException, 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 = null;

    switch (productName) {
    case "Oracle":
        //Consulta paginada
        query = "SELECT codcia, codcia||' - '||nomcia2";
        query += " FROM pnt001";
        query += " where grupo = '" + grupo + "'";
        query += " order by codcia";
        break;
    case "PostgreSQL":
        //Consulta paginada
        query = "SELECT codcia, codcia||' - '||nomcia2";
        query += " FROM pnt001";
        query += " where CAST(grupo AS text) = '" + grupo + "'";
        query += " order by codcia";
        break;
    }

    pstmt = con.prepareStatement(query);
    //System.out.println(query);

    ResultSet r = pstmt.executeQuery();

    while (r.next()) {
        String cia = new String(r.getString(1));
        String nombre = new String(r.getString(2));

        listCias.put(nombre, cia);
        sorted = sortByValues(listCias);

    }
    //Cierra las conecciones
    pstmt.close();
    con.close();

}

From source file:org.enlacerh.util.Seg007.java

/**
* Leer registros en la tabla//from   w w  w .  j  a  v  a  2 s.c om
* @throws NamingException 
* @throws IOException 
**/
public void counter(Object filterValue) throws SQLException, NamingException, IOException {
    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 = null;
        String[] veccouser = pcoduser.split("\\ - ", -1);

        switch (productName) {
        case "Oracle":
            query = "SELECT count_seg007(" + Integer.parseInt(grupo) + ",'"
                    + ((String) filterValue).toUpperCase() + "','" + veccouser[0].toUpperCase()
                    + "') from dual";
            break;
        case "PostgreSQL":
            query = "SELECT count_seg007(" + Integer.parseInt(grupo) + ",'"
                    + ((String) filterValue).toUpperCase() + "','" + veccouser[0].toUpperCase() + "')";
            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.Sgc005.java

/**
 * Leer Datos de paises/*from  w w w  . j  ava 2s.c  o m*/
 * @throws NamingException 
* @throws IOException 
 **/
public void select(int first, int pageSize, String sortField, Object filterValue)
        throws SQLException, ClassNotFoundException, NamingException {

    //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 * FROM";
    query += "(select query.*, rownum as rn from";
    query += "(SELECT A.CODIGO, A.DESCR ";
    query += " FROM SGC005 A";
    query += " GROUP BY A.CODIGO, A.DESCR";
    query += ")query ) ";
    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()) {
        Sgc005 select = new Sgc005();
        select.setZcodigo(r.getString(1));
        select.setZdesc(r.getString(2));

        //Agrega la lista
        list.add(select);
    }
    //Cierra las conecciones
    pstmt.close();
    con.close();

}

From source file:org.openbizview.util.Maillista.java

/**
* Leer registros en la tabla/*from w  ww .  j ava 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

        if (idgrupo == null) {
            idgrupo = " - ";
        }
        if (idgrupo == "") {
            idgrupo = " - ";
        }

        String[] vecidgrupo = idgrupo.split("\\ - ", -1);

        String query = "";

        switch (productName) {
        case "Oracle":
            query = "SELECT count_maillista('" + ((String) filterValue).toUpperCase() + "','" + vecidgrupo[0]
                    + "','" + instancia + "') from dual";
            break;
        case "PostgreSQL":
            query = "SELECT count_maillista('" + ((String) filterValue).toUpperCase() + "','" + vecidgrupo[0]
                    + "','" + instancia + "')";
            break;
        case "Microsoft SQL Server":
            query = "SELECT DBO.count_maillista('" + ((String) filterValue).toUpperCase() + "','"
                    + vecidgrupo[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.Maillista.java

/**
 * Actualiza mailconfig/*w  w w  . ja  v a 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 MAILLISTA";
            query += " SET mail = ?";
            query += " where IDGRUPO = ? and IDMAIL = ? and instancia = '" + instancia + "'";
            break;
        case "PostgreSQL":
            query = "UPDATE MAILLISTA";
            query += " SET mail = ?";
            query += " where cast(IDGRUPO as text) = ? and cast(IDMAIL as text) = ? and instancia = '"
                    + instancia + "'";
            break;
        }

        //System.out.println(query);
        pstmt = con.prepareStatement(query);
        pstmt.setString(1, mail.toLowerCase());
        pstmt.setString(2, idgrupo);
        pstmt.setString(3, idmail);
        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"), "");
            }
            mail = "";
        } 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:com.google.enterprise.connector.salesforce.storetype.DBStore.java

public DocListEntry getDocsImmediatelyAfter(String checkpoint) {
    DatabaseMetaData dbm = null;
    Connection connection = null;

    try {/*from  www  .j ava  2 s  .  c  o m*/

        connection = ds.getConnection();
        connection.setAutoCommit(true);

        dbm = connection.getMetaData();
        //get the most recent database row after 'checkpoint'
        if (dbm.getDatabaseProductName().equals("MySQL")) {
            Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
                    ResultSet.CONCUR_READ_ONLY);
            String update_stmt = "select crawl_set,insert_timestamp,UNCOMPRESS(crawl_data) as cdata from "
                    + this.instance_table + " where crawl_set>" + checkpoint + "  LIMIT 1";
            logger.log(Level.FINER, update_stmt);
            ResultSet rs = statement.executeQuery(update_stmt);

            boolean ret_rows = rs.first();

            if (!ret_rows) {
                logger.log(Level.FINER, "No Rows Returned.");
                connection.close();
                return null;
            }
            BigDecimal crawl_set = null;
            String crawl_data = null;
            while (ret_rows) {
                crawl_set = rs.getBigDecimal("crawl_set");
                //crawl_data = rs.getString("crawl_data");
                crawl_data = rs.getString("cdata");
                ret_rows = rs.next();
            }

            rs.close();
            statement.close();
            connection.close();

            //BASE64 DECODE 
            byte[] byte_decoded_entry = org.apache.commons.codec.binary.Base64
                    .decodeBase64(crawl_data.getBytes());
            crawl_data = new String(byte_decoded_entry);

            logger.log(Level.INFO, "Returning from DBStore. Index Value: " + crawl_set.toPlainString());
            logger.log(Level.FINEST, "Returning from DBStore. " + crawl_data);
            DocListEntry dret = new DocListEntry(crawl_set.toPlainString(), crawl_data);
            return dret;
        }
    } catch (Exception ex) {
        logger.log(Level.SEVERE, "Unable to retrieve docListEntry " + ex);
    }
    return new DocListEntry(checkpoint, null);
}

From source file:org.openbizview.util.Instanciasusr.java

/**
* Leer Datos de nominas para asignar a menucheck
* @throws NamingException //from   ww  w.  ja  v a 2 s  . c  o  m
* @throws SQLException 
* @throws IOException 
**/
private void selectInstanciasUsr() throws NamingException, SQLException {

    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 trim(coduser), trim(coduser)||' - '||trim(desuser)";
        query += " from bvt002";
        query += " order by coduser";
        break;
    case "PostgreSQL":
        query = "Select trim(coduser), trim(coduser)||' - '||trim(desuser)";
        query += " from bvt002";
        query += " order by coduser";
        break;
    case "Microsoft SQL Server":
        query = "Select coduser, coduser||' - '||desuser";
        query += " from bvt002";
        query += " order by coduser";
        break;
    }

    //System.out.println(query);

    pstmt = con.prepareStatement(query);
    ////System.out.println(query);

    r = pstmt.executeQuery();

    while (r.next()) {
        String cat1 = new String(r.getString(1));
        String descat1 = new String(r.getString(2));

        listUsr.put(descat1, cat1);
        sorted = sortByValues(listUsr);

    }
    //Cierra las conecciones
    pstmt.close();
    con.close();

}

From source file:org.talend.cwm.db.connection.ConnectionUtils.java

/**
 * DOC xqliu Comment method "isOdbcMssql". bug 9822
 * /*  w  ww  .  j av  a  2 s  .c  o  m*/
 * @param connection
 * @return
 * @throws SQLException
 */
public static boolean isOdbcMssql(java.sql.Connection connection) throws SQLException {
    @SuppressWarnings("deprecation")
    DatabaseMetaData connectionMetadata = org.talend.utils.sql.ConnectionUtils
            .getConnectionMetadata(connection);
    if (connectionMetadata.getDriverName() != null
            && connectionMetadata.getDriverName().toLowerCase().startsWith(DatabaseConstant.ODBC_DRIVER_NAME)
            && connectionMetadata.getDatabaseProductName() != null
            && connectionMetadata.getDatabaseProductName().equals(DatabaseConstant.ODBC_MSSQL_PRODUCT_NAME)) {
        return true;
    }
    return false;
}

From source file:org.talend.cwm.db.connection.ConnectionUtils.java

public static boolean isOdbcProgress(java.sql.Connection connection) throws SQLException {
    @SuppressWarnings("deprecation")
    DatabaseMetaData connectionMetadata = org.talend.utils.sql.ConnectionUtils
            .getConnectionMetadata(connection);
    if (connectionMetadata.getDriverName() != null
            && connectionMetadata.getDriverName().toLowerCase().startsWith(DatabaseConstant.ODBC_DRIVER_NAME)
            && connectionMetadata.getDatabaseProductName() != null
            && connectionMetadata.getDatabaseProductName().toLowerCase()
                    .indexOf(DatabaseConstant.ODBC_PROGRESS_PRODUCT_NAME) > -1) {
        return true;
    }//from  w  w w. j a  va2 s.  co m
    return false;
}

From source file:org.talend.cwm.db.connection.ConnectionUtils.java

/**
 * DOC zshen Comment method "isOdbcMssql". feature 10630
 * /*from  w w w  .j a  v  a2s.  c  o m*/
 * @param connection
 * @return
 * @throws SQLException
 */
public static boolean isOdbcExcel(java.sql.Connection connection) throws SQLException {
    @SuppressWarnings("deprecation")
    DatabaseMetaData connectionMetadata = org.talend.utils.sql.ConnectionUtils
            .getConnectionMetadata(connection);
    if (connectionMetadata.getDriverName() != null
            && connectionMetadata.getDriverName().toLowerCase().startsWith(DatabaseConstant.ODBC_DRIVER_NAME)
            && connectionMetadata.getDatabaseProductName() != null
            && connectionMetadata.getDatabaseProductName().equals(DatabaseConstant.ODBC_EXCEL_PRODUCT_NAME)) {
        return true;
    }
    return false;
}