1 12 package org.openbravo.base.secureApp; 13 14 import java.sql.*; 15 16 import javax.servlet.ServletException ; 17 18 import org.openbravo.data.FieldProvider; 19 import org.openbravo.database.ConnectionProvider; 20 import org.openbravo.exception.*; 21 import org.openbravo.data.UtilSql; 22 23 25 public class DefaultValuesData implements FieldProvider { 26 public String columnname; 27 28 public String getField(String fieldName) { 29 if (fieldName.equalsIgnoreCase("columnname")) 30 return columnname; 31 else { 32 System.out.println("Field does not exist: " + fieldName); 33 return null; 34 } 35 } 36 37 39 public static String select(ConnectionProvider connectionProvider, String param1, String param2, String param3, String param4) throws ServletException { 40 String strSql = "SELECT " + param1 + " AS COLUMNNAME"; 41 strSql = strSql + " FROM " + param2 + " "; 42 strSql = strSql + " WHERE isActive = 'Y' "; 43 strSql = strSql + " AND isDefault = 'Y' "; 44 strSql = strSql + " AND AD_Client_ID IN (" + param3 + ") "; 45 strSql = strSql + " AND AD_Org_ID IN (" + param4 + ") "; 46 strSql = strSql + " ORDER BY AD_Client_ID"; 47 48 Statement st = null; 49 ResultSet result; 50 String resultado=""; 51 52 try { 53 st = connectionProvider.getStatement(); 54 result = st.executeQuery(strSql); 55 56 if (result.next()) { 57 resultado = UtilSql.getValue(result, "COLUMNNAME"); 58 } 59 result.close(); 60 } catch(SQLException e){ 61 System.out.println("SQL error in query: " + strSql + "Exception:"+ e); 62 throw new ServletException ("@CODE=" + Integer.toString(e.getErrorCode()) + "@" + e.getMessage()); 63 } catch(NoConnectionAvailableException ec){ 64 System.out.println("Connection error in query: " + strSql + "Exception:"+ ec); 65 throw new ServletException ("@CODE=NoConnectionAvailable"); 66 } catch(PoolNotFoundException ep){ 67 System.out.println("Pool error in query: " + strSql + "Exception:"+ ep); 68 throw new ServletException ("@CODE=NoConnectionAvailable"); 69 } catch(Exception ex){ 70 System.out.println("Exception in query: " + strSql + "Exception:"+ ex); 71 throw new ServletException ("@CODE=@" + ex.getMessage()); 72 } finally { 73 try { 74 connectionProvider.releaseStatement(st); 75 } catch(Exception ignore){ 76 ignore.printStackTrace(); 77 } 78 } 79 return(resultado); 80 } 81 } 82 | Popular Tags |