Making function to select

Hi, i want to make a funtion using JSP and JAVA, making the connection to BD and SELECt from JAVA and show the array in JSP.
I can do it in put all them in a single line but i can�t put them in an array
ex. select cant, sku from units;
6 apple
3 banana
4 orange
and i want to see like that array but only can see 6,3,4,apple,banana,orange
the script is:
in java file
import java.io.*;
import java.sql.*;
import java.util.*;
public class BasedeDatos {
private Connection connection;
private Statement statement;
// Construyendo el objeto
public BasedeDatos() throws Exception {
// Cargando el Driver
Class.forName("net.sourceforge.jtds.jdbc.Driver");
// Conectado a la BD
connection = DriverManager.getConnection("jdbc:jtds:sqlserver://localhost:1433/thinks","aaaa","bbbb" );
statement = connection.createStatement();
public List Consulta( String campos, String tabla, String num_campos) throws SQLException {
List ListadeCampos = new ArrayList();
// Realiza el query
ResultSet results = statement.executeQuery( " SELECT "+ campos + " FROM "+ tabla +" ");
// Obteniendo los resultados en un arreglo
while ( results.next() ) {
     ListadeCampos.add (results.getString( 1 ));
     ListadeCampos.add (results.getString( 2 ));
return ListadeCampos;
// Cerrando el statements y terminado la conexion
protected void finalize() {
// Cerrando la conexion
try {
statement.close();
connection.close();
// Proceso de SQLException al cerrar la conexion
catch ( SQLException sqlException ) {
sqlException.printStackTrace();
and in the JSP file
<%@ page import = "java.util.*" %>
<%@ page import = "autentifica.*" %>
<jsp:useBean id = "BaseDatos" scope = "request" class = "autentifica.BasedeDatos" />
<%
String campos = "cant, sku";
String num_campos = "2";
String tabla = "units";
out.print(BaseDatos.Consulta(campos , tabla, num_campos));
%>

You should work with an iterator and avoid the out.println.
So, you would get something like this :
<jsp:useBean id="rondeLijst" class="java.util.ArrayList" scope="session"/>
<% int teller = 0;
for (Iterator i = rondeLijst.iterator(); i.hasNext(); )
if (teller == 11)
{ %>
<tr>
<th class="mopoTekst" scope="col">sel</th>
<th scope="col"><div align="right" class="mopoTekst"></div></th>
<th scope="col"><div align="right" class="mopoTekst"></div></th>
<th scope="col"><div align="left" class="mopoTekst">meterronde</div></th>
<th scope="col"><div align="right" class="mopoTekst">leidingen</div></th>
<th scope="col"><div align="right" class="mopoTekst">meters</div></th>
<th scope="col"><div align="right" class="mopoTekst">te lezen </div></th>
<th scope="col"><div align="right" class="mopoTekst">in CMB </div></th>
</tr>
<% teller = 0;
Meterronde meterronde = (Meterronde) i.next();
%>
<tr class="mopoTekst">
<td><input name="radioRonde" type="radio" value="<%=meterronde.getWijkRonde()%>"></td>
<td><div align="right"><%=meterronde.getWijknummer()%></div></td>
<td><div align="right"><%=meterronde.getRondenummer()%></div></td>
<td><div align="left"><%=meterronde.getOmschrijving()%></div></td>
<td ><div align="right"><%=meterronde.getAantalContractueleLeidingen()%></div></td>
<td ><div align="right"><%=meterronde.getAantalActieveMeters()%></div></td>
<td><div align="right"><%=meterronde.getAantalTeLezen()%></div></td>
</tr>
<% teller++;
} %>

Similar Messages

  • Using function in select statement

    Hi,
    CREATE FUNCTION [dbo].[udf_testFunction] 
    @value int
    RETURNS int
    AS
    BEGIN
    -- Declare the return variable here
    declare @returnValue int
    set @returnValue = @value*2;
    return @returnValue;
    END
    GO
    create table #Temp
        EmpID int, 
        EmpName Varchar(50)
    insert into #Temp(EmpID,EmpName) values(1,'Name1');
    insert into #Temp(EmpID,EmpName) values(2,'Name2');
    insert into #Temp(EmpID,EmpName) values(3,'Name3');
    insert into #Temp(EmpID,EmpName) values(4,'Name4');
    insert into #Temp(EmpID,EmpName) values(5,'Name5');
    select EmpID,EmpName, [dbo].[udf_testFunction](EmpID), [dbo].[udf_testFunction](EmpID)*EmpID,[dbo].[udf_testFunction](EmpID)+2 from #Temp
    In the above select statement i used [dbo].[udf_testFunction]() function 3 times. But i want to use only once and reuse it.
    Something like 
    select EmpID,EmpName, testfunctionvalue,testfunctionvalue*EmpID,testfunctionvalue+2 from #Temp
    Please advise me.... Thanks in Advance...

    You can use this code: 
    WITH cte
    AS ( SELECT EmpID ,
    EmpName ,
    [dbo].[udf_testFunction](EmpID) AS testfunctionvalue
    FROM #Temp
    SELECT EmpID ,
    EmpName ,
    testfunctionvalue ,
    testfunctionvalue * EmpID ,
    testfunctionvalue + 2
    FROM cte
    But using scalar functions in select clause can hurt the performance. Please see this link: 
    SQL Server Scalar User Defined Function Performance
    T-SQL Articles
    T-SQL e-book by TechNet Wiki Community
    T-SQL blog

  • PL/SQL Function in Select statement

    Hi
    I am calling a function in select statement. The query works in Toad and PL/SQL developer except SQL plus and disconnecting Oracle connection.
    The error is “ERROR at line 1: ORA-03113: end-of-file on communication channel”.
    When I called the same query from BC4J View Object the error message is “java.sql.SQLException: No more data to read from socket”.
    Can any one advise me please?
    Thanks
    Srini

    Srini
    I've seen similar cases in the past with 9.2.0.x (x <= 5). What Oracle version are you using? It's worth checking the bug database (I can't just now - I don't have a valid support id in my current contract). And as Warren says, post your SQL query.
    HTH
    Regards nigel

  • Functionality for Select and Save layout in a report output

    Hi,
    I had developed a report program containing several fields in the output and requires the Functionality for Select layout and Save layout in a report output.
    Please suggest.
    Thanks,
    Shariq.

    While calling the FM for List Display ( "REUSE_ALV_LIST_DISPLAY" or "REUSE_ALV_GRID_DISPLAY" ) set the Parameter I_SAVE for Setting the Layout and Selecting a different Layouts.
    The possible values for I_SAVE are "A", "U", "X" or others. Depending on the requiement you can set different values for the Parameter I_SAVE.
    ' ' = display variants cannot be saved
    Defined display variants (e.g. delivered display variants) can be selected for presentation independently of this flag.
    Changes can not be saved.
    'X' = standard save
    Display variants can be saved as standard display variants.
    User-specific saving is not possible.
    'U' = only user-specific saving
    The user can only save display variants user-specifically
    'A' = standard and user-specific saving
    The user can save a display variant user-specifically and
    as standard display variant. The user chooses in the display variant
    save popup.
    Reward points if helpful.

  • Using java function in select statement

    Hi,
    I am trying to use java function in select statement.
    public class ClassA{
         private static String MyConst = "foo";
         public static String functionA(){
              return MyConst;
    in my query I have:
    select
         ClassA.functionA() AS id,
         groupId AS newID,
    from
         myChannel[now]
    ClassA is part of the application (no need to import).
    I get and error of Invalid Expression on ClassA.functionA().
    I also tried to declare the function in the processor element:
    <wlevs:processor id="proc">
         <wlevs:function function-name="A" exec-methode="functionA">
              <bean class="mtPackage.ClassA"/>
         </wlevs:function>
    <wlevs:processor>
    but then I get a different error in the processor XML file:  "An InvocationTargetException was encoutered while attemting to register the user defind function A. The message was null"
    What am I missing here?

    Hi,
    From the above description, you have tried two manners to call method functionA() in the user defined  class ClassA. One uses java cartridge manner directly and the other try to use user defined function manner.
    For the java cartridge manner, the following CQL query should work if the ClassA is really included in the OEP app. I have done similar test before, it works.
    select
         ClassA.functionA() AS id,
         groupId AS newID,
    from
         myChannel[now]
    For user defined function manner, I think two things you need to change:
    1. Need to declare the function in the EPN assembly file(under META-INF/spring/), not component configuration file(under META-INF/wlevs/). The following is an example:
    <wlevs:processor id="proc">
         <wlevs:function function-name="A" exec-methode="functionA">
              <bean class="mtPackage.ClassA"/>
         </wlevs:function>
    </wlevs:processor>
    2. Call the user defined function in the CQL query in the component configuration file under processor. For example:
    select A() from myChannel
    Regards,
    XiYing

  • Calling User definedTable valued function in Select

    Hello,
    I Created a UserDefined Table Valued Function in HANA.
    I need to call it in Select Statement Statement.
    For Example
    Select Func(col1) as test,col2 from tablename;
    While using UserDefined Table Valued Function in above select statement
    I am getting following error
    cannot use procedure or table function in select projection
    Please help me

    Dont think you can do that Krishna,
    A Tabel UDF is expected to return a row of results and not just a scalar value. A SELECT <value> on the other hand can only expect a single value. Maybe you could try SELECT  (SELECT TOP 1 <column name> from TABLEUDF() ) from....
    Regards,
    Nehal.

  • I have a 60G classic with a non-functioning center select button. Can I set a specific playlist and change settings by hooking up to my PC and then maintain those settings and that playlist once I go remote?

    I have a 60G classic with a non-functioning center select button. Can I set a specific playlist and change settings by hooking up to my PC and then maintain those settings and that playlist once I go remote?

    I'm having a little trouble understanding the part about your password having to be reset. Why is that happening??
    Let's start with Firefox's settings:
    (1) You can configure the password manager feature on this tab:
    orange Firefox button (or Tools menu) > Options > Security
    There is a checkbox to enable/disable the feature.
    There also is a "Saved Passwords" button to review and remove any passwords you do not want Firefox to keep.
    That tab also has a feature to set a Master Password so that no one can use your saved passwords without knowing the Master Password. You may need to exit Firefox in order for Firefox to ask for that again.
    Related articles:
    * [[Password manager - Remember, delete and change saved passwords in Firefox]]
    * [[Use a Master Password to protect stored logins and passwords]]
    (2) Site-specific permissions
    If you want to use the password manager for other sites but NOT a particular site, you can configure that in the Permissions Manager.
    In a new tab, type or paste '''about:permissions''' in the address bar and press Enter.
    After the page loads, use the search box in the upper left corner to narrow down the list to the site you want to configure. Highlight the site on the left side, and on the right side, choose Block under Store Passwords.
    (3) Form autocomplete suggestions
    Separate from passwords, Firefox remembers entries you've made into forms (in most cases) and lists the matching ones below the form field in a drop-down.
    To clear a suggestion, press the down arrow key to highlight it and press the Delete key.
    To turn off this feature, see this article: [[Control whether Firefox automatically fills in forms with your information]].
    To review and selectively edit or delete form history entries, you need an add-on. For example, you could try this one: https://addons.mozilla.org/firefox/addon/form-history-control/

  • Unable to call local function in select statement.

    Hi all,
    I am unable to call the local function in select statement in below scenario.
    DECLARE
    l_cnt NUMBER;
    FUNCTION FUN1 RETURN NUMBER
    AS
    BEGIN RETURN 2;
    END;
    BEGIN
    SELECT FUN1 INTO l_cnt FROM DUAL;
    DBMS_OUTPUT.PUT_LINE(l_cnt );
    END;
    /Any alternate way to call local function in select statement?
    Thanks
    Ram.

    Hi,
    Sorry, you can't call a locally defined function in a SQL statement, even if that SQL statement is in a PL/SQL block where the function is in scope.
    This applies to packages, also. If a function is not declared in the package spec, but only in the package body, then you can't call it from SQL statements in the package body.
    Why do you want a locally defined function? Why not a function defined outside the procedure?

  • F4 functionality on selection screen

    Hi,
    i am having One requirement that  need to create f4 functionality on selection screen.
    please give me solution on that

    Hi,
    When you refer your selection screen element to a data element which has a F4 option, then it gives you a F4 help automatically.
    If not try using match code objects.
    Refer to the below related threads
    match code
    match code
    Match Code
    Match code
    Matchcodes are defined in two stages in Abap/4 Dictionary:
    1) The revelant table and fields are stipulated in matchcode object. A matchcode object describes the set of all possible search paths for a search item.
    2) One or more matchcode ID can be defined for a matchcode object. A matchcode ID describes a special search path for a search term.The fields or combination of fields via which the search is to take place is defined in the matchcode ID.
    In the initial screen of Data Dictionary,
    Enter a name for your new object, click on the Matchcode radio button, and press the Create button.
    Enter descriptive text as you enter your primary table on the Attributes screen and press the Save button.
    The primary table represents the primary source table for the subsequent field search. Secondary tables can also be maintained at this point by double-clicking on the primary table or pressing the Tables button. These tables must link to the primary table through foreign keys.
    The Maintain Matchcode Object attributes screen.
    At this point you have the option of creating the matchcode as a local object or attaching it to a transport request. After you have done this, click on the Save button
    The Create Object Catalog Entry screen.
    As the status bar reflects, the mandatory key fields are transferred automatically .If you want, you can press the Fields button and maintain any selection fields you want. At this point you need to click on the green arrow to go back to the Maintain Attributes screen.
    The Maintain Matchcode Object (Fields) screen.
    The next step in the creation process is to activate the matchcode object. The status of the object is New and Saved .
    The matchcode attributes prior to activation.
    The status is now set to Active and Saved. Next you need to create a matchcode ID or your object will be incomplete.
    To do this, click the Matchcode IDs button.
    The matchcode attributes after activation.
    The system will prompt you to create a new ID if one does not exist To do this, click on the Yes button.
    A prompt to Create Object.
    On the Create Matchcode ID screen , specify a matchcode ID number, valid input ranges from all of the alphabet, and any number. You can also click on the down arrow to view a range of valid entries.
    The Create Matchcode ID dialog box.
    Let's view some possible entries this list window shows a number of matchcode IDs and a short description of each. Choose one and click on the green arrow.
    A Matchcode hit list.
    Follow these steps we learned to maintain selection fields for this matchcode ID, be sure to enter an Update type, and click on Save . At this point, you can enter further selection criteria by pushing the Selection Criteria button.
    Maintenance of matchcode attributes.
    In the Maintain Selection Conditions screen, you can enter and maintain fields and selection criteria for your matchcode IDs. Here is an example of a requirement of a Material Number not greater than the value of 8888 .When finished, click Save and the green arrow to go back.
    The Maintenance Selection Conditions dialog box.
    Now all you have to do is activate your matchcode ID and your new object is ready to use
    Generate and use the matchcode.
    Reward if helpful.
    Regards,
    Narendra.

  • Is possible in a dialog screen attach a field functional like select-option

    hi,
       Is it possible - in a dialog screen - to attach a field that has functionality like Select-options fields?
    And if so - how?
    and information about complex_selections_dialog

    Hi,
    Look at the below links
    module pool programming " to add selection-option on screen"
    module pool programming " to add selection-option on screen"
    Regards
    Sudheer

  • Call function with select arguments

    Hi Gurus,
    I have problem to call function inside select statements as follow:
    select a.ID_ELE2, a.ID_ELE3, a.DT_FIS_YR, c.NU_FIS_PER, c.dt,
    (case
    when c.ld is null then
    GET_LD_CHECK (a.DT_FIS_YR,c.NU_FIS_PER, a.ID_ELE3, a.ID_ELE2) -- 1
    -- GET_LD_CHECK ('2009',7, '8010', '7493') --- 2
    else
    c.ld
    end ) description
    from ACCOUNT a, TRANSACTION c
    where a.DT_FIS_YR ='2009'
    and a.ID_ELE3 <> '0000'
    and c.TY_SRC not in ('CL', 'CN')
    and a.DT_FIS_YR = c.nu_fis_yr
    and a.AK = c.AK_FGCHAR
    and trim(a.ID_ELE3) ='8010'
    and c.NU_FIS_PER <> 14
    order by 1,4,5,6
    the 1 doesn't output result but the 2 it does! How can pass the select result to the function?
    Thanks in advance for your help.
    Ben

    The statement / function call seems to be ok. So there are not much chances left for your call to return different (=non) values.
    1) It could be that you have different values in the column then during your test call.
    2) Maybe your function raises an error and that error is supressed in some ugly WHEN OTHERS EXCEPTION => Solution: Get rid of the error handler.
    3) datatype conversion. For example if a.dt_fis_yr is a number value, then you should test with number values and not with strings. GET_LD_CHECK (2009,7, '8010', '7493'). Same logic goes for the other paramters, make sure the datatype is correct and matches the function parameter.

  • Error when execute a planning function on selected line

    Hello together, 
    we are using SAP BusinessObjects Analysis 1.4 SP9 (1.4.9.3241, Office 2013) and SAP BW 7.3 SP 11 (SAPKW73011).
    When executing a planning function on an selected line in the crosstab, the following error appears:
    The VBA Coding used is from HowTo Execute a Planning Function on Selected Lines in an Analysis for Office Workbook.
    The Code worked fine with an older version of SAP BO Analysis and Excel 2007.
    Going to debugging:
    As you can see in the screenshot, the selected line (Dimension "0PRODUCT") is selected correctly.
    The settings for the planning function are the following:
    Thank you in advance for any advice.
    Best regards
    Alex

    Hello together, 
    we are using SAP BusinessObjects Analysis 1.4 SP9 (1.4.9.3241, Office 2013) and SAP BW 7.3 SP 11 (SAPKW73011).
    When executing a planning function on an selected line in the crosstab, the following error appears:
    The VBA Coding used is from HowTo Execute a Planning Function on Selected Lines in an Analysis for Office Workbook.
    The Code worked fine with an older version of SAP BO Analysis and Excel 2007.
    Going to debugging:
    As you can see in the screenshot, the selected line (Dimension "0PRODUCT") is selected correctly.
    The settings for the planning function are the following:
    Thank you in advance for any advice.
    Best regards
    Alex

  • How to hide F8 function on selection screen.

    Hi,
    How to hide F8 function on selection screen.

    Just create a customer status and SET this status in your INITIALIZATION block.
    <i>You can copy the standard status from program RSSYSTDB status %_00.</i>
    Regards

  • Functionality that select the current tag

    I am trying to add functionality that selects the current
    tag. Like the tag editor does, but without the pop-up. I haven't
    got vary far on figuring it out and I would appriciate some help.

    What do you mean by the "current" tag? To me, that means the
    one that is
    already (i.e. currently) selected.
    Randy
    > I am trying to add functionality that selects the
    current tag. Like the tag editor does, but without the pop-up. I
    haven't got vary far on figuring it out and I would appriciate some
    help.

  • Parameterized function in select

    Hi Folks,
    How can i pass parameterized function in a select statement.
    The function has four parameters, those are : NUMBER, NUMBER, VARCHAR2, Collection of Varchar2.
    The return type of the function is Collection of Numbers.
    i am trying like this :
    select banker_id from table(cast(FETCH_BANKERS(:PID,:bankerId,:bankerName,:businessId,cast(:businessIds as tt_varchar))as tab_typ_bankers))It is failing with error : ORA-00932: inconsistent datatypes: expected - got CHAR

    See the answers in your other thread
    how to use a function in select clause

Maybe you are looking for

  • Our company portal is not compatible with the latest version so I want to reverse the last upgrade

    I upgrade Mozilla to the latest release and I cannot log into company intranet because is not supported. I need to reverse the upgrade or to reinstall Mozilla to an earlier version before 6.0 thanks,

  • Error while installing AD exchange connector

    Hi All, When I m trying to install exchange connector 9.1.1.7.0 in OIM 11.1.1.3.0 I m getting the following error the error occurred while importing connector xml files please help me in this regards DOBJ.XML_IMPORT_ERROR oracle.iam.reconciliation.ex

  • Interactive form Exception

    Hello,   I am creating a WebDynpro application with Interactive form. I have created single context element(pdfSource of binay and attached it to pdf source of Interactive form elemnt). I build and deploy the application. When i run the application,

  • Photoshop CS6 Installation Failure

    I have tried numerous times to install PS6 but every time I get the Installation Failed error message. Id, Fl, Ai, Dw, Acrobat X have all installed without any problems. I have a new Mac Pro 3.33 GHz 6-Core Intel Xenon with OS X 10.8.1 I do still hav

  • Need to upgrade from snow leopard to lion

    Hello, I am running up-to-date 10.6.8 (Snow Leopard) on mid-2009 iMac 2.66 ghz Intel dual core I need to upgrade to Lion. I don't want to upgrade to Mountain Lion. Pointers? Thanks!