Skip to main content
se añadieron 292 caracteres en el cuerpo
Origen Enlace
try {
        // Step 1: Allocate a database Connection object
        Class.forName("com.ddtek.jdbc.openedge.OpenEdgeDriver");
        conn = DriverManager.getConnection("jdbc:datadirect:openedge://127.0.0.1:5556;databaseName=dbdb",
                "sys", "sys123"); // <== Check!
        // database-URL(hostname, port, default database), username, password

        // Step 2: Allocate a Statement object within the Connection
        stmt = conn.createStatement();
 
        // Step 3: Execute a SQL SELECT query
        
        
        String sqlStr = "select -sum(pvpne) as tot from ISIDB.PUB.\"historico-alm\" where clprv = "+ clientep_path[1] + "' and emp='04' "
                + "and tmv like 'e%c' AND femov between TO_DATE('"+ f_iniciop_path[2] +"') and TO_DATE('"+ f_finp_path[3] +"') with (NOLOCK) "
                + "union " 
                + "select sum(pvpne) as tot from ISIDB.PUB.\"historico-alm\" where clprv = '"+ clientep_path[1] + "' and emp='04' "
                + "and tmv like 's%c' AND femov between TO_DATE('"+ f_iniciop_path[2] +"') and TO_DATE('"+ f_finp_path[3] +"') with (NOLOCK)";

        return sqlStr;
        // Print an HTML page as the output of the query
        res += "["; // Echo for debugging
        ResultSet rset = stmt.executeQuery(sqlStr); // Send the query to the server
        int count = 0;
        while (rset.next()) {
            if(count > 0) {
                res += ",";
            }
            
            // Print a paragraph <p>...</p> for each record
            res += rset.getString("tot");
            
            count++;
        }
        res += "]";
        conn.close();
    } catch (SQLException ex) {
        ex.printStackTrace();
    } catch (ClassNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return res;
}
// Step 2: Allocate a Statement object within the Connection
        stmt = conn.createStatement();
 
        // Step 3: Execute a SQL SELECT query
        
        
        String sqlStr = "select -sum(pvpne) as tot from ISIDB.PUB.\"historico-alm\" where clprv = "+ cliente + "' and emp='04' "
                + "and tmv like 'e%c' AND femov between TO_DATE('"+ f_inicio +"') and TO_DATE('"+ f_fin +"') with (NOLOCK) "
                + "union " 
                + "select sum(pvpne) as tot from ISIDB.PUB.\"historico-alm\" where clprv = '"+ cliente + "' and emp='04' "
                + "and tmv like 's%c' AND femov between TO_DATE('"+ f_inicio +"') and TO_DATE('"+ f_fin +"') with (NOLOCK)";

        return sqlStr;
        // Print an HTML page as the output of the query
        res += "["; // Echo for debugging
        ResultSet rset = stmt.executeQuery(sqlStr); // Send the query to the server
        int count = 0;
        while (rset.next()) {
            if(count > 0) {
                res += ",";
            }
            
            // Print a paragraph <p>...</p> for each record
            res += rset.getString("tot");
            
            count++;
        }
        res += "]";
        conn.close();
    } catch (SQLException ex) {
        ex.printStackTrace();
    } catch (ClassNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return res;
}
try {
        // Step 1: Allocate a database Connection object
        Class.forName("com.ddtek.jdbc.openedge.OpenEdgeDriver");
        conn = DriverManager.getConnection("jdbc:datadirect:openedge://127.0.0.1:5556;databaseName=dbdb",
                "sys", "sys123"); // <== Check!
        // database-URL(hostname, port, default database), username, password

        // Step 2: Allocate a Statement object within the Connection
        stmt = conn.createStatement();
        // Step 3: Execute a SQL SELECT query
        
        
        String sqlStr = "select -sum(pvpne) as tot from ISIDB.PUB.\"historico-alm\" where clprv = "+ p_path[1] + "' and emp='04' "
                + "and tmv like 'e%c' AND femov between TO_DATE('"+ p_path[2] +"') and TO_DATE('"+ p_path[3] +"') with (NOLOCK) "
                + "union " 
                + "select sum(pvpne) as tot from ISIDB.PUB.\"historico-alm\" where clprv = '"+ p_path[1] + "' and emp='04' "
                + "and tmv like 's%c' AND femov between TO_DATE('"+ p_path[2] +"') and TO_DATE('"+ p_path[3] +"') with (NOLOCK)";

        
        // Print an HTML page as the output of the query
        res += "["; // Echo for debugging
        ResultSet rset = stmt.executeQuery(sqlStr); // Send the query to the server
        int count = 0;
        while (rset.next()) {
            
            // Print a paragraph <p>...</p> for each record
            res += rset.getString("tot");
            
            count++;
        }
        res += "]";
        conn.close();
    } catch (SQLException ex) {
        ex.printStackTrace();
    } catch (ClassNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return res;
}
Origen Enlace

UNION Select en JAVA. ¿Qué hago mal?

Lo primero decir que tengo muy pocas nociones de java, pero lucho e intento defenderme como un loco.

Estoy creando un applet y funciona todo bien pero tengouna consulta que lleva un union y me da resultado en blanco. Una select normal sin union no tengo problema, pero en esta en cuestión sí y no se que hago mal. La base de datos que estoy trabajando es Progress. Código que tengo:

// Step 2: Allocate a Statement object within the Connection
        stmt = conn.createStatement();

        // Step 3: Execute a SQL SELECT query
        
        
        String sqlStr = "select -sum(pvpne) as tot from ISIDB.PUB.\"historico-alm\" where clprv = "+ cliente + "' and emp='04' "
                + "and tmv like 'e%c' AND femov between TO_DATE('"+ f_inicio +"') and TO_DATE('"+ f_fin +"') with (NOLOCK) "
                + "union " 
                + "select sum(pvpne) as tot from ISIDB.PUB.\"historico-alm\" where clprv = '"+ cliente + "' and emp='04' "
                + "and tmv like 's%c' AND femov between TO_DATE('"+ f_inicio +"') and TO_DATE('"+ f_fin +"') with (NOLOCK)";

        return sqlStr;
        // Print an HTML page as the output of the query
        res += "["; // Echo for debugging
        ResultSet rset = stmt.executeQuery(sqlStr); // Send the query to the server
        int count = 0;
        while (rset.next()) {
            if(count > 0) {
                res += ",";
            }
            
            // Print a paragraph <p>...</p> for each record
            res += rset.getString("tot");
            
            count++;
        }
        res += "]";
        conn.close();
    } catch (SQLException ex) {
        ex.printStackTrace();
    } catch (ClassNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return res;
}

Gracias!