"for each..." statement

I just wonder if java support "for each" statement? such as, I don't know how many items and names in a array, so I like to list out all. then how to do it?
for example, in asp:
'----------codes start-----------
for each item in session.contents
response.write item &"="& session(item)
next
'-----------codes----------------
how can I change this code to Java, so I can get each session name?
thank you

hi, i don't know if you have had answer to your problem allready, so i provide you with some manual pagess that wil be helpful.
...i don't know if you have found your way to J2EE APi allready...
HTTPSession:
http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/http/HttpSession.html
and there you will find method getAttributeNames(), from there you may work with while(attribNamesEnumeration.hasNext()) { ... }
but as you ask something that might as well be from PHP, then i suspect that you're dealing with JSPs, and therefore you could be wanting help not about session, but HttpServletRequest:
http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/http/HttpServletRequest.html
and there you see methods (not directly in this class, but in its superclass -- sorry if that's confusing, important thing is taht you may use those methods) like:
getParameter(String name)
getParameterMap()
getParameterNames()
getParameterValues(String name)
there's no point in copying that api here.... so go check it out yourself...
put basicaly you may use getParameterNames() to get all names of parameters that are sent with this request, and in case any of parameters has many values (like.in.this/request.html?param=value1&param=value2&param=value3) you could use getParameterValues() method to get all values of that parameter
HTH

Similar Messages

  • GROUP BY - Is there a way to have some sort of for-each statement?

    Hi there,
    This discussion is a branch from https://forums.oracle.com/thread/2614679
    I data mart I created for a chain of theatres. The fact table contain information about ticket sales, and I have a some dimensions including DimClient and DimTime.
    Here is an example of each table:
    FactTicketPurchase
    TICKETPURCHASEID
    CLIENTID
    PRODUCTIONID
    THEATREID
    TIMEID
    TROWID
    SUMTOTALAMOUNT
    60006
    2527
    66
    21
    942
    40
    7
    60007
    2527
    72
    21
    988
    36
    6
    60008
    2527
    74
    21
    1001
    40
    6
    60009
    2527
    76
    21
    1015
    37
    6
    60010
    2527
    79
    21
    1037
    39
    6
    DDL for FactTicketPurchase
    CREATE TABLE FactTicketPurchase(
    TicketPurchaseID NUMBER(10) PRIMARY KEY,
    ClientID NUMBER(5) CONSTRAINT fk_client REFERENCES DimClient,
    -- ProductionID NUMBER(5) CONSTRAINT fk_prod REFERENCES DimProduction,
    -- TheatreID NUMBER(5) CONSTRAINT fk_theatre REFERENCES DimTheatre,
    TimeID NUMBER(6) CONSTRAINT fk_time REFERENCES DimTime,
    -- TRowID NUMBER(5) CONSTRAINT fk_trow REFERENCES DimTRow,
    SumTotalAmount NUMBER(22) NOT NULL);
    DimClient
    CLIENTID
    CLIENT#
    NAME
    TOWN
    COUNTY
    2503
    1
    LEE M1
    West Bridgford
    Nottingham
    2504
    2
    HELEN W2
    Hyson Green
    Nottingham
    2505
    3
    LEE M3
    Lenton Abbey
    Nottingham
    2506
    4
    LORA W4
    Beeston
    Nottingham
    2507
    5
    SCOTT M5
    Radford
    Nottingham
    2508
    6
    MINA W6
    Hyson Green
    Nottingham
        ..cff.
    DDL for DimClient
    CREATE TABLE DimClient(
    ClientID NUMBER(5) PRIMARY KEY,
    Name VARCHAR2(30) NOT NULL);
    DimTime
    TIMEID
    FULLDATE
    YEAR
    SEASON
    MONTH
    MONTHDAY
    WEEK
    WEEKDAY
    817
    02-MAR-10
    2010
    Spring
    3
    2
    9
    3
    818
    03-MAR-10
    2010
    Spring
    3
    3
    9
    4
    819
    04-MAR-10
    2010
    Spring
    3
    4
    9
    5
    820
    05-MAR-10
    2010
    Spring
    3
    5
    9
    6
    821
    06-MAR-10
    2010
    Spring
    3
    6
    9
    7
    822
    07-MAR-10
    2010
    Spring
    3
    7
    9
    1
    DDL for DimTime
    CREATE TABLE DimTime(
    TimeID NUMBER(6) PRIMARY KEY,
    Year NUMBER(4) NOT NULL,
    Season VARCHAR2(20));
    I have the following analysis request to perform on this data mart:
    Top 5 clients by value of ticket sale for each season
    For this requirement I came up with the following query:
    SELECT * FROM
    (SELECT FacTIC.ClientID, DimCLI.Name, SUM(SumtotalAmount) SumTotalAmount, DimTIM.Season
    FROM FactTicketPurchase FacTIC, DimClient DimCLI, DimTime DimTIM
    WHERE FacTIC.ClientID = DimCLI.ClientID
    AND FacTIC.TimeID = DimTIM.TimeID
    AND Season = 'Spring'  AND Year = 2010
    GROUP BY Season, FacTIC.ClientID, DimCLI.Name
    ORDER BY Season ASC, SumTotalAmount DESC)
    WHERE rownum <=5;
    As you can see, in line 06 of the above query, I am explicitly specifying the season for the query to return.
    However what I would like to do is just one query that could autocratically go through the seasons and years available in the time dimension in a fashion similar to a FOR-EACH statement. This way, if we get more years added to the time dimension, we wouldn't have to amend the query.
    Is this possible?
    Regards,
    P.

    I think I fixed it!
    The trick was to look into the r_num value. As soon as I added it to my query I started to see how r_num was being calculated and I realised that I had to add Season to my partition, right after Year.
    SELECT Year, Season, TotalAmount, Name
    FROM (
       SELECT   DimCLI.Name
       ,        DimTIM.Year
       ,        DIMTIM.Season
       ,        SUM(FacTIC.SumTotalAmount) TotalAmount
       ,        RANK() OVER (PARTITION BY Year, Season
                             ORDER BY SUM(FacTIC.SumTotalAmount) DESC
                            ) AS r_num
       FROM     FactTicketPurchase FacTIC
       ,        DimClient DimCLI
      ,         DimTime DimTIM
       WHERE    FacTIC.ClientID = DimCLI.ClientID
       AND      FacTIC.TimeID = DimTIM.TimeID
       GROUP BY DimTIM.Year
       ,        DimTIM.Season
       ,        DimCLI.Name
    WHERE r_num <= 5 -- Need to amend this line on my data sample to show 2 rows.
    ORDER BY Year, Season, TotalAmount DESC;
    Looking at my data sample, I got the following:
    YEAR
    SEASON
    TOTALAMOUNT
    CLIENTID
    2010
    Autumn
    29
    2504
    2010
    Autumn
    26
    2503
    2010
    Spring
    25
    2503
    2010
    Spring
    14
    2506
    2010
    Summer
    26
    2506
    2010
    Summer
    26
    2504
    2010
    Winter
    28
    2503
    2010
    Winter
    26
    2506
    2011
    Autumn
    23
    2506
    2011
    Autumn
    14
    2503
    2011
    Spring
    25
    2505
    2011
    Spring
    13
    2503
    2011
    Summer
    21
    2505
    2011
    Summer
    14
    2503
    2011
    Winter
    19
    2505
    Now, looking at my real data, (considering the top 5 rows, not the top 2), I got:
    YEAR
    SEASON
    TOTALAMOUNT
    NAME
    2010
    Autumn
    141
    BUSH M225
    2010
    Autumn
    140
    DIANA W66
    2010
    Autumn
    136
    HANA W232
    2010
    Autumn
    120
    DIANA W220
    2010
    Autumn
    120
    WILSON M459
    2010
    Spring
    137
    DAVID M469
    2010
    Spring
    125
    ALEX M125
    2010
    Spring
    124
    PETER M269
    2010
    Spring
    115
    ZHOU M463
    2010
    Spring
    114
    TANIA W304
    2010
    Summer
    138
    JANE W404
    2010
    Summer
    105
    MINA W8
    2010
    Summer
    97
    DAVID M275
    2010
    Summer
    96
    CLINTON M483
    2010
    Summer
    93
    ANNA W288
    2011
    Spring
    12
    LUISE W20
    2011
    Spring
    7
    ANNA W432
    2011
    Spring
    7
    LEE M409
    2011
    Spring
    7
    CHRIS W274
    2011
    Spring
    7
    HELEN W136
    2011
    Spring
    7
    LILY W114
    2011
    Spring
    7
    LUISE W348
    2011
    Spring
    7
    LIU M107
    2011
    Spring
    7
    VICTORY W194
    2011
    Spring
    7
    DIANA W240
    2011
    Spring
    7
    HELEN W120
    2011
    Spring
    7
    LILY W296
    2011
    Spring
    7
    MATTHEW M389
    2011
    Spring
    7
    PACO M343
    2011
    Spring
    7
    YANG M411
    2011
    Spring
    7
    ERIC M101
    2011
    Spring
    7
    ALEX M181
    2011
    Spring
    7
    SMITH M289
    2011
    Spring
    7
    DIANA W360
    2011
    Spring
    7
    MATTHEW M63
    2011
    Spring
    7
    SALLY W170
    2011
    Spring
    7
    JENNY W258
    2011
    Spring
    7

  • Problem For/Each statement (or the problem is the MouseListener...)

    Hi guys,
    I'm making a program in java for school.
    Now I have this:
              for(Stap2TrampolineModel trampoline : lijstTrampolines)
                   trampoline = new Stap2TrampolineModel(0,215,100,"Poing",lijstKinderen); //model
                   trampolineView = new Stap2TrampolineView(trampoline); //view
                   trampolineController = new Stap2TrampolineController(trampoline, trampolineView); //controller
                   trampolineView.setBounds(trampoline.getXInvoer(),trampoline.getYInvoer(),trampoline.getFormaat()+1,20);
                   add(trampolineView);
                   repaint();
    and in the mouselistener this:
    public void mouseClicked( MouseEvent e )
              System.out.println(lijstTrampolines.size());
              // Onderzoek of met de rechterknop is geklikt
    if( e.isMetaDown() )
         // x = e.getX(); (for later needs)
    //y = e.getY(); (for later needs)
    lijstTrampolines.add(trampoline);
    repaint();
    The program should display a "trampoline" when I click...but it doesnt. It is added to the list, because I can see that in the console because of the System.out.println
    But it doesn't show the display I want. When I delete the for each statement, it does show the "trampoline". So the mouselistener works (it gets added when I click) and the arraylist works (it shows that in the console), but the for each statement doesnt work...
    Anyone knows how to solve this problem?

    Where is this foreach loop located? In inialisation presumably. But that's over and done with when your mouseListener is called. I'd guess your list is empty when the loop is called, and it does nothing.
    Your mouse listener, when it adds a trampoline must also add a trampoline view object. And the repaints don't do you any good, use revalidate() after adding a trampoline view to recalculate the layout.

  • Variable Use in For-Each statement

    Hello Gurus-
    I am having an issue using a variable i've created in a for each statement. Here is the code i'm using
    My objective is to create a variable based on the kind of invoice. If the invoice is a proof or reprint, one copy should be printed. If it's a final invoice, I need two copies.
    <?xdoxslt:set_variable($_XDOCTX, 'x', 0)?>
    for-each<?if: Print_Additional_Header_Text_ID238='PROOF'?><?xdoxslt:set_variable($_XDOCTX, 'x', 1)?><?end if?>
    <?if: Print_Additional_Header_Text_ID238='REPRINT'?><?xdoxslt:set_variable($_XDOCTX, 'x', 1)?><?end if?>
    <?if:not ( Print_Additional_Header_Text_ID238)?><?xdoxslt:set_variable($_XDOCTX, 'x',2)?><?end if?>
    <?xdoxslt:get_variable($_XDOCTX,'x')?><?for-each@section:xdoxslt:foreach_number($_XDOCTX,1,$x,1)?>
    for-each is the loop i'm using to repeat sections of the invoice.
    When I run the preview with the last for-each print, i get an error that says "variable not defined:'x' "
    But when i remove the last for each the correct variable, 1 or 2, will show in the invoice.
    My question is: How can I use the variable 'x' in <?for-each@section:xdoxslt:foreach_number($_XDOCTX,1,$x,1)?>
    TIA
    Darius
    Edited by: 852460 on May 24, 2011 8:31 AM
    Edited by: DEK17 on Jul 20, 2011 1:15 PM

    Probably, this will help
    http://winrichman.blogspot.com/search/label/multiple%20copy
    Try
    <?for-each@section:xdoxslt:foreach_number($_XDOCTX,1,get_variable($_XDOCTX, 'x'),1)?>
    or
    <?for-each@section:xdoxslt:foreach_number($_XDOCTX,1,xdoxslt:get_variable($_XDOCTX, 'x'),1)?>

  • Set height size for each state enabling browser scrollbar if needed..

    I'm working on a flex project, completely new to it. I'm trying to resize my application based on the set height size for each state. I'd like the wrapper to resize in the browser so that the  browser's scroll bar appears if needed. hope this makes sense....
    My enitial opening page I've set the height to 1000. now when I click on a link to another state from this page, we'll call it 'home' which i have set to 2000
    The page opens in its 2000 height but no scroll bar appears to scroll down in the browser...
    If anyone's done this or knows how to, I'd really appreciate your input.

    I've done something similar with a few of my apps, you have to use a little javascript on the html page and the ExternalInterface class in your app. Basically, you need to resize the "browser's" height based on your flash file.  So here's quick example:
    In your html template page (which you can edit in your flashbuilder project panel ->html-template->indext.template.html)
    in your html add the jscript function:
    <script type="text/javascript">
             function setWindowHeight(heightVal){
                 document.getElementById('theWindow').style.height=heightVal; // make sure to give the body tag an id of 'theWindow' or whatever
    </script>
    In your flashbuilder app you need to call the javascript fx, you can use the ExternalInterface class for this:
      ExternalInterface.call('setWindowHeight',val+'px');
    you need to send the jscript fx the height of your container or whatever you want it resized to....

  • Jdbc driver creates new thread for each statement with a query timeout set

    I am profiling a web application that is using the Microsoft JDBC driver, version 1.1 to connect to a sql server 2005 database. Each java.sql.Statement that is created, within the application, gets a query timeout value set on it ( statement.setQueryTimeout(...) ).
    I have discovered that the JDBC driver creates a new thread to monitor each Statement and the query timeout value. When the application is under load these threads are getting created faster then they are being destroyed and I am concerned that this will cause a performance problem in production.
    One option I have is to remove the query timeout value and the monitor threads will not be created, another is to change JDBC drivers.
    I'm curious is there any way to control this behavior so that these threads are not created or are managed more efficiently.  Is there a workaround that anyone is aware of?   Is this considered a bug?
    I have found a similar bug here for the 2000 driver:
    http://support.microsoft.com/default.aspx/kb/894552
    Cheers

    Hi,
    Thank you for using the Microsoft SQL Server JDBC driver.  You are correct that a new thread is started to monitor the query timeout when a statement is executed.  This is a potential performance issue that we may look at addressing in the upcoming v1.2 release.  The current behavior is not configurable.  The only workaround with the v1.1 driver is to limit your use of query timeouts to only those statements which you reasonably might expect to actually time out.
    We do take customer feedback very seriously, so if anyone else is concerned about this particular issue, please chime in and we will be able to give it appropriate weight.
    --David Olix [MSFT]

  • Tax Accounts - Is it necessary to have separate tax acct. for each state

    I am new at this:
    Is it necessary to have separate AR/AP/ account for each tax jurisdiction like state county etc?\
    Or do the sales tax reports for payments in SAP produce outstanding taxes per jurisdiction.
    I would prefer only one Sales Tax account and hope to have SAP produce the taxes due per jurisdiction.
    Mike

    Thanks Suda.
    So I only need to setup two tax accounts:
    1.  One tax account for tracking the AR taxes
    2.  One tax account for tracking the AP taxes
    So, to report the taxes to the different tax jurisdictions, SAP should be able to break then down individually for us to pay them.
    I am new at this ... so please be patient.
    Mike

  • How to get Runtime for each statement in abap program

    Is there any tool which tells the runtime of each statement in our program..apart from sto5 and se30
    Thanks in advance
    PRASANNA

    Determining the calculation time for calculating the tangent of 1. Since the runtime of the statement is less than a microsecond, the runtime of several executions in an inner loop is measured. The exection time for the loop itself is also measured in order to deduct it as an offset. These measurements are executed several times in an outer loop and the mean value is created using division by n0. Through division by ni, the runtime of an individual statement is determined.
    DATA: t0    TYPE i,
          t1    TYPE i,
          t2    TYPE i,
          t3    TYPE i,
          t4    TYPE i,
          tm    TYPE f,
          no    TYPE i VALUE 100,
          ni    TYPE i VALUE 1000,
          res   TYPE f.
    DO no TIMES.
      GET RUN TIME FIELD t1.
      DO ni TIMES.
        res = TAN( 1 ).
      ENDDO.
      GET RUN TIME FIELD t2.
      GET RUN TIME FIELD t3.
      DO ni TIMES.
      ENDDO.
      GET RUN TIME FIELD t4.
      t0 = t0 + ( ( t2 - t1 ) - ( t4 - t3 ) ).
    ENDDO.
    tm = t0 / ni / no.
    Source: SAP Help.
    Regards,
    Santosh

  • Is there a for-each statement in XSQL like the one in XSL?

    I'm trying to do the following:
    <?xml version="1.0" ?>
    - <!-- <?xml-stylesheet type="text/xsl" href="/dvd/xsl/admin/listuser.xsl"?>
    -->
    - <database>
    - <request>
    - <parameters>
    - <row>
    <checkboxuser>jonathan</checkboxuser>
    </row>
    - <row>
    <checkboxuser>james</checkboxuser>
    </row>
    - <row>
    <checkboxuser>steve</checkboxuser>
    </row>
    - <row>
    <checkboxuser>richard</checkboxuser>
    </row>
    </parameters>
    - <session>
    <access>0</access>
    <user>malik</user>
    <adminfirstname>Malik</adminfirstname>
    <adminlastname>Graves-Pryor</adminlastname>
    </session>
    - <cookies>
    <JServSessionIdroot>v647ogyd8n</JServSessionIdroot>
    </cookies>
    </request>
    - <allusers>
    - <userinfo>
    <first-name>Jonathan</first-name>
    <last-name>Terry</last-name>
    <email>[email protected]</email>
    <user-name>jonathan</user-name>
    <password>terry</password>
    <access-level>1</access-level>
    </userinfo>
    </allusers>
    </database>Now as you can see, I have 4 instances of <checkboxuser> in my XSQL page. These values are being passed in from checkboxes on the previous page. Is there an XSQL command that will say something like <xsql:for-each select="/database/request/parameters/checkboxuser"> ?
    So that it'd look something like this in the original code:
    <?xml version="1.0"?>
    <!--<?xml-stylesheet type="text/xsl" href="/dvd/xsl/admin/listuser.xsl"?>-->
    <database connection="dvddb" xmlns:xsql="urn:oracle-xsql">
    <xsql:include-request-params/>
    <xsql:query id-attribute="" tag-case="lower" rowset-element="allusers" row-element="userinfo">
    SELECT FIRSTNAME AS "FIRST-NAME",
    LASTNAME AS "LAST-NAME",
    EMAIL AS "EMAIL",
    USERNAME AS "USER-NAME",
    PASSWORD AS "PASSWORD",
    ACCESSLEVEL AS "ACCESS-LEVEL"
    FROM LKUP_USER
    WHERE USERNAME = '<xsql:for-each select="/database/request/parameters/checkboxuser">'
    ORDER BY ACCESSLEVEL
    </xsql:query>
    </database>Or something like that... The XSL works fine, but not when I want to pull info from the DB.. :)
    Malik Graves-Pryor

    Ok I got a friend of mine to load everything up for me using 'javac' on he command line with -verbose and he got this back:
    C:\oracle\ora81>javac -verbose MultiValuedParam.java
    [parsed MultiValuedParam.java in 453 ms]
    [loaded C:\Oracle\ora81\lib\oraclexsql.jar(oracle/xml/xsql/XSQLActionHandlerImpl
    .class) in 62 ms]
    [loaded C:\jdk1.2.2\jre\lib\rt.jar(java/lang/Object.class) in 0 ms]
    [loaded C:\Oracle\ora81\lib\oraclexsql.jar(oracle/xml/xsql/XSQLActionHandler.cla
    ss) in 0 ms]
    [loaded C:\jdk1.2.2\jre\lib\rt.jar(java/sql/SQLException.class) in 15 ms]
    [loaded C:\jdk1.2.2\jre\lib\rt.jar(java/lang/Exception.class) in 0 ms]
    [loaded C:\jdk1.2.2\jre\lib\rt.jar(java/lang/Throwable.class) in 0 ms]
    [loaded C:\jdk1.2.2\jre\lib\rt.jar(java/io/Serializable.class) in 0 ms]
    MultiValuedParam.java:10: Package javax.servlet.http not found in import.
    import javax.servlet.http.*;
    ^
    MultiValuedParam.java:11: Package org.w3c.dom not found in import.
    import org.w3c.dom.*;
    ^
    [checking class MultiValuedParam]
    2 errors
    [done in 1266 ms]Any clues on what needs to be done to get those last two working? He has the oraclexsql.jar file listed in the system environment variable section of win2k.
    Thanks!
    Malik Graves-Pryor

  • Help with combining for each statements

    Hi,
    I am trying to get the count of computers in each active directory OU which I am able to do. I am also trying to get the count of computers in each OU that belong to the Test_Group (P) membership group which I can do as well. I just don't know how to output
    both on the same line? So I would like to select name, computer, then the value of $Test as well? Below is an example of what I trying to achieve, right now I can only get the name and computers to output?
    Name  Computers  Test
    US       100             3
    CA        20              1
    import-module activedirectory
    foreach ($ou in Get-ADOrganizationalUnit -filter * -SearchScope 1){
    $computers = 0 + (get-adcomputer -filter * -searchbase $ou.distinguishedname).count
    $Test = (Get-ADGroupMember -Identity “Test_Group (P)”).count
    $ou | add-member -membertype noteproperty -name Computers -value $computers -force
    $ou | select name,computers

    Got it nm
    $cmplist=get-adcomputer-Filter"cn
    -like '*L*'"

  • ID 5.5 Interact. PDF, cannot remove white background for Multi-States and buttons.

    Hi
    I am working on an Interactive PDF Portfolio document. The problem I have is with Multi-State object feature with several buttons going to states that need to be exported as a SWF and imported back into InDesign 5.5. See, the background of my entire doc. is GREY, but when I import the SWF (as directed in Lynda.com videos correctly) and export the entire doc as Interactive PDF and view it in Adobe Acrobat Pro (version 10.1.1) is when all the trouble starts.
    When I try to get rid of the WHITE background around the Multi-State objects and the buttons for them (using Select Object Tool and then control+click on it to change the Properties to Transparent Background Appearance) it does not change, even when I go forward and backward to the page.
    Does the option of removing white background and making it transparent work only for Animation, but not Multi-State feature with buttons?
    Can anyone suggest any other tecnique to create a nice slide show that works in Interactive PDF in ID CS5.5? Please..
    Sincerely,
    in need of help,
    Eve

    I have 8 Multi-State objects in one stack on the left and the 8 buttons for each state in the stack on the right. The background of my document is dark grey. There is space inbetween Multi-State objects and the buttons that show the grey background. But after exporting as SWF the Multi-States together with the buttons and placing the SWF back in the PDF file, the space inbetween Multi-States and buttons that is supposed to show the grey background appears white. The problem is that I cannot even change this white background to transparent in Acrobat Pro, as well. I used to do that to animations and it worked, but not in this case.

  • For each help in JSP ?

    Hi all
    Does JSP support for each statement ??
    Actually i need to cycle through each post variable like this in ASP
    for each tempvarname in request.form
    value1 = request.form(tempvarname)
    pass=pass&value1
    next
    I am unable to do this JSP...
    Can somebody help ?

    Use JSTL's c:forEach tag.
    <c:forEach items="${param}" var="item">
        ${item.key} = ${item.value}<br/>
    </c:forEach>That said, the need for this is a smell. Rethink your approach.

  • One connection for each sql statment?

    Hi there!
    Can I use only one connection for several stataments or prepared statements? or
    Do I have to use 1 connection for each statement?
    After an insert, how can I know row id assigned by SQL Server (authonumeric)?
    Thanks a lot in advanced.
    LJ

    >
    One of the updates to the JDBC API in Java 1.4 has
    been a getGeneratedKeys() call, which (if you
    requested them) gives you the keys that were
    generated.
    Good idea here, evnafets. I tried it with Oracle recently, but it didn't work. I wasn't aware of a driver that did implement it. I'll try MySQL to see. Thanks.
    You would probably need an up to date JDBC driver, but
    I have seen this work in mySQL. Maybe it might solve
    this problem once and for all.
    Apart from that you can try select @@Identity from the
    server to get the id
    Or that old awful, unreliable hack of select (max)
    (shudder)
    Any other suggestions?Some folks like having a single table for key generation. Keys are unique across all tables that way. Using that scheme with before insert triggers can mean just a query on the key table. - MOD

  • Tricking for-each iterators

    I've just discovered that a piece of my code is modifying a collection that's being iterated over through a for-each statement.
    My question is: Bug, or Feature?
      List<Integer> xs = new ArrayList<Integer>();
            for (int i=0; i<10; i++)
                xs.add(new Integer(i));
            for (Integer x : xs)
                // Adding the lines below would give us the ConcurrentModificationException
                // as expected.
                //xs.remove(x);
                //xs.add(new Integer(x+1));
                // But the line down here doesn't cause a problem.
                // It's very cheeky, since it certainly does violate the Iterator principle!
                // It gets away with it since break is called
                // the iterator ever does its next() call, which checks to see
                // if there has been a modification.
                // Is this a bug or a feature?
                if ( x == 9 ) {
                    xs.remove(x);
                    break;
            for (Integer x : xs) {
                System.out.println(x);
            }

    This is pretty strange though, the following code explores an irregularity in iterators:
            System.out.println("Iterator method");
            List<Integer> xs = new ArrayList<Integer>();
            for (int i = 0; i < 10; i++) {
                xs.add(new Integer(i));
            // The safe way of adding or removing elements is thus:
            int i = 0;
            for (Iterator<Integer> iterator = xs.iterator(); iterator.hasNext();) {
                if (i == 10) {
                    System.out.println("THIS LINE SHOULD NEVER HAPPEN"); // THIS LINE GETS EXECUTED PAST ITERATOR IF (*) IS PRESENT!
                i++;
                Integer x = iterator.next();
                System.out.println(x);
                if (x == 9) {
                // This is the proper way of removing an element
                //iterator.remove();   
                // The lines below would work, but this isn't safe
                xs.remove(x); //(*) THIS LINE CAUSES LINE ABOVE TO BE EXECUTED PAST ITERATOR!
                //break; // BUT IF THIS LINE IS PRESENT, THERE ARE NO PROBLEMS!
            System.out.print("Contents of xs: ");
            System.out.println(xs);The output is as follows:
    Iterator method
    0
    1
    2
    3
    4
    5
    6
    7
    8
    9
    Exception in thread "main" java.util.ConcurrentModificationException
            at java.util.AbstractList$Itr.checkForComodification(AbstractList.java:372)
            at java.util.AbstractList$Itr.next(AbstractList.java:343)
            at sandbox.MutableForEach.main(MutableForEach.java:69)
    THIS LINE SHOULD NEVER HAPPEN
    Java Result: 1The odd thing is that the line that ought never happen does in fact happen - why did the for loop ignore the hasNext() call which must have returned false? Of course, since I've done an illegal remove(), we break the iterator functionality, and so we cannot expect good behaviour. Yet if we include the break statement below the line marked (*), the output is:
    Iterator method
    0
    1
    2
    3
    4
    5
    6
    7
    8
    9
    Contents of xs: [0, 1, 2, 3, 4, 5, 6, 7, 8]This is "correct" behaviour in the sense that the iterator is never again used due to the break, but is it formally correct, or is it just a side-effect of the current implementation of for-loops and iterators? Can this behaviour be relied on in the future?
    Edited by: Nicolas.Wu on Feb 24, 2008 6:55 AM

  • Using Images for each button

    I am trying to create a spry menu that has 5 buttons and each button will have 3 different images for each state (something like this http://jjcstudios.com/woof_wallet/ ) I was going to use the insert > navigation bar but I read that this method creates a lot of extra javascript and they recommended using Spry instead. Can anyone point me in a direction to create a clean method of doing java rollovers or modifying the spry menu so it will work as a rollover. thanks john

    John,
    To place the javascript in an external file, grab the code that is producedon the page
    function MM_preloadImages() { //v3.0
      var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
        var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
        if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
    function MM_findObj(n, d) { //v4.01
      var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
        d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
      if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
      for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
      if(!x && d.getElementById) x=d.getElementById(n); return x;
    function MM_nbGroup(event, grpName) { //v6.0
      var i,img,nbArr,args=MM_nbGroup.arguments;
      if (event == "init" && args.length > 2) {
        if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
          img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
          if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
          nbArr[nbArr.length] = img;
          for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
            if (!img.MM_up) img.MM_up = img.src;
            img.src = img.MM_dn = args[i+1];
            nbArr[nbArr.length] = img;
      } else if (event == "over") {
        document.MM_nbOver = nbArr = new Array();
        for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
          if (!img.MM_up) img.MM_up = img.src;
          img.src = (img.MM_dn && args[i+2]) ? args[i+2] : ((args[i+1])? args[i+1] : img.MM_up);
          nbArr[nbArr.length] = img;
      } else if (event == "out" ) {
        for (i=0; i < document.MM_nbOver.length; i++) {
          img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
      } else if (event == "down") {
        nbArr = document[grpName];
        if (nbArr)
          for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
        document[grpName] = nbArr = new Array();
        for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
          if (!img.MM_up) img.MM_up = img.src;
          img.src = img.MM_dn = (args[i+1])? args[i+1] : img.MM_up;
          nbArr[nbArr.length] = img;
    and place it in a file called menu.js or similar.
    In your page place the following in between the <head></head> tags
    <script src="menu.js" type="text/javascript"></script>
    to link the Javascript.
    If you want to put menu.js in a different folder, make sure you adjust the link accordingly, like "js/menu.js"
    Ben

Maybe you are looking for

  • How can I rename open PDF files on my android tablet

    How can I rename open files on android tablet

  • Position Of Buttons @Pop-up

    Hi all, I have an pop-up . And i use it in 2-3 views. I want to change the positions of yes/no/cancel buttons. Is it possibe ? Best Regards, Orhan

  • Audigy SE + Vista Iss

    I just bought a new Audigy SE because my old Li've and integrated sound weren't well supported in Vista. However, I'm still having issues. Things seem to work okay on the desktop with the latest drivers, but I've tried playing Bioshock and Crysis and

  • Can we build dimensions in empty outline using "DynamicDimensionBuild" meth

    Hi there........ Iam trying to build dimension in outline which is empty by using "dynamic dimension Build" Method... it is saying the error is "Database outline is empty". But Whenever outline contains one or more dimensions then I can build another

  • Allow duplicate member names in Essbase application

    Hi, I have checked "Allow Duplicate Members" for my ASO application (system 11.1.2.1.00). By doing this, I can create members of same name across dimensions. But alias names can't still be duplicated. Is there anyway to use same alias names for multi