Ver Mensaje Individual
  #11 (permalink)  
Antiguo 18/09/2013, 14:21
CRauda
 
Fecha de Ingreso: septiembre-2010
Mensajes: 91
Antigüedad: 13 años, 7 meses
Puntos: 9
Respuesta: Más de un return's?

Como te dije, ambas maneras son correctas, pero entre menos variables crees y menos valores setees menor uso de memoria tendras, es por eso que si te fijas hago return con valores directos, a menos que sea necesario, como en el caso de verificar si es un valor numerico y si es menor de 10 ponerle un cero al inicio, en ese caso si utilice una variable, pero en las demas hago un return directamente con el valor que se refiere a la respuesta obtenida, sino me quedaria de esta forma:

Código Java:
Ver original
  1. private String ejecutaAccion(int accion, String valor,String valor2,String valor3,String Tabla,String Tabla2) throws SQLException{
  2.             String sql = "";
  3.             String valorReturn = null;
  4.             if (accion == 1){
  5.                sql = "SELECT CTIME campo FROM " + Esquema + "." + Tabla + " WHERE CLABRQ IN (select CLABRQ from " + Esquema + "." + Tabla2 + " where cjbcrd='" + valor + "')";
  6.             }
  7.             if(accion == 2){
  8.                 sql = "select ATMPOR campo from " + Esquema2 + "." + Tabla + "  where asplit='" + valor + "'";
  9.             }
  10.             if(accion == 3){
  11.                 sql = "select JESTTM campo from " + Esquema + "." + Tabla + " where JWRKO2= " + valor2 + " and JWRKO1= " + valor;
  12.             }
  13.             if(accion == 4){
  14.                 sql = "select YTMVAL campo from " + Esquema2 + "." + Tabla + " where ysplit ='" + valor + "'";
  15.             }
  16.             try {
  17.                 stmt = as.connection.createStatement();
  18.                 rs = stmt.executeQuery(sql);  
  19.                 while(rs.next()){
  20.                     if (rs.getString("campo") == null || rs.getString("campo").equals("") || rs.getString("campo").equals("null")){
  21.                         valorReturn = "0";
  22.                     }else{
  23.                         valorReturn = (rs.getString("campo")).toString();
  24.                         if(isNumeric(valorReturn)){
  25.                             if(Integer.parseInt(valorReturn) < 10){
  26.                                 valorReturn = "0" + valorReturn;
  27.                             }
  28.                         }
  29.                     }
  30.                 }
  31.             } catch (SQLException e) {
  32.                 e.printStackTrace();
  33.                 valorReturn = "ND";
  34.             }   finally{
  35.                 return valorReturn;
  36.             }
  37.         }
  38.  
  39.     public boolean isNumeric(String input) {
  40.       boolean Numerico = false;
  41.       try {
  42.         Integer.parseInt(input);
  43.         Numerico = true;
  44.       }
  45.       catch (NumberFormatException e) {
  46.         //e.printStackTrace();
  47.        
  48.       }
  49.       return Numerico;
  50.     }


Que al final es lo mismo, pero con mas uso de memoria, imagina un caso real, 600 usuarios conectados al mismo tiempo en el sistema usando los recursos del servidor... entre mas recursos consumas, mas lento se pondra el sistema y mas probabilidades de saturar el servidor tendras. Saludos.