Display boolean

Hi....
I am very new to Oracle and trying to learn SQL/ PL/SQL.I want to display a boolean b using a dbms_output.put_line.
I use the following code:
declare
b boolean:=true;
begin
dbms_output.put_line(b);
end;
It gives the following error:
ERROR at line 1:
ORA-06550: line 4, column 3:
PLS-00306: wrong number or types of arguments in call to 'PUT_LINE'
ORA-06550: line 4, column 3:
PL/SQL: Statement ignored
Kindly suggest..
Thanks,
Alisha.

You can only output string, numbers, or dates (implicitly converted to strings) through dbms_output.put_line.
To output boolean values, you'll either need to write a function that will convert the boolean to a number or string, or use if/else logic to display the values:
if b then
  dbms_output.put_line('True');
else
  dbms_output.put_line('False');
end if;

Similar Messages

  • Display boolean in

    Hi,
    i'm trying to capture the boolean results at the RESULT.vi but i couldn't get a notion on how to do it.
    Can anyone help me?
    Thank you!
    Attachments:
    ex op (SubVI).vi ‏52 KB
    RESULT.vi ‏16 KB

    Hi microes,
    you already connected the boolean with the connector pane, so you only needed an indicator in the main vi (Result.vi).
    But:
    - you also have to wire a result to the indicator in the subvi
    - you better give names to controls/indicators to avoid property nodes without proper labels!
    - do as much as possible outside of structures (loops, cases, sequences) to get cleaner block diagrams (see subvi, lower right of the block diagram)
    - act according to style guide: left to right wiring, no hidden wires, straight wires (deactivate automatic wire routing, if this is ok for you!), use labels
    - your "result" indicator in the subvi only holds the value of the last iteration - is this wanted behaviour?
    - to AND with TRUE is like multiplying with 1 or adding zero
    - keep in mind: using "default if unwired" in case structures easily results in unwanted behaviour
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome
    Attachments:
    RESULT.vi ‏15 KB
    ex op (SubVI).vi ‏42 KB

  • Displaying Boolean data

    Probably something silly I'm doing or not doing.
    I'm using Yes/No data from an Access db and I was expecting
    it to display true/false on the Dreamweaver generated web page BUT
    instead I get one or zero (1/0). Any suggestions, much
    appreciated

    oilovlam,
    Not knowing your full set-up I can't be sure, but this is
    most likely a function of your database. Access treats true/false
    values differently than most databases. It's OK for a teaching tool
    and desktop applications, but not really intended for web
    applications.
    Can you tell me what chapter in Jeffrey's book this comes
    from? I believe it was updated in the latest version and I might be
    able to tell you how it was handled. It could be that I changed the
    database so that it was no longer a true/false field. Like I said,
    Access is not really up to serious web application use.Others will
    differ with that, but I stand by it. I would recommend using MySQL
    for the exercises instead. There are quick and easy MySQL
    installers for (WAMP5 for Windows and MAMP for Mac) that will have
    you up and running in no time.
    Just a quick note to optimize your CF code a bit. You only
    need cfoutput if you are outputting a variable. You can also
    combine your cfifs. See below.
    <cfif rs_tourDetail.exerciseReqd>Yes<cfelseif NOT
    rs_tourDetail.exerciseReqd>No</cfif>
    Best of luck,
    Bob
    http://bobflynn.info/

  • cfselect display boolean values

    I am trying to create a cfselect on a search page that checks for a boolean value in an access database. It works when I put a 1 or 0 in the option/values, but I want it to say yes or no instead of 1 or 0  -- novice - thank you-- jim
    <label for="Addressed">Addressed:</label>
    <cfselect name="addressed" id="addressed" >
    <option value="">Select an option.</option>
    <option value="1">1</option>
    <option value="0">0</option>
    </cfselect

    What would happen if you changed this:
    <option value="1">1</option>
    to this
    <option value="1">yes</option>

  • How can I get all the values of a String array profile property using javascript?

    I am trying to build functionality into our site that records all products added to the basket against a user's profile.
    I have so far been able to store the product codes against the profile as a property using Ajax:
           var dataString = ":formid=addProduct&:formstart=/apps/thread/templates/page_product/jcr:content/par/produc t/formstart&:redirect=/content/thread/en/user/cart.html&productId=151515:profile="+profile ;
                         $.ajax({ 
                type: "POST", 
                url: "/content/women/evening/dresses/l-k-bennett-davinadress.html", 
                data: dataString, 
                success: function(data) { 
    In this example I have hardcoded a product ID of 151515.
    In order to save the property as a multi string field you simply replace &productId=151515 with &productId=151515&productId=131313&productId=141414 or as many extra values as you want to build into that string. This stores a productId property against a user profile.
    The issue comes from calling that data back. Using var value = CQ_Analytics.ProfileDataMgr.getProperty("productId") I can get the first value of this array (or the single value if only one is stored).
    However there does not seem to be a way to get any of the other stored values in the array using getProperty. Does anyone know how I can achieve this?

    Hi,
    Don't think that's possible. Even if it were, you wouldn't be able to use/display BOOLEAN type in SQL.
    If you just aim to see what they are, you could do something like this
    select text
      from all_source
    where owner = 'SYS'
       and name = 'DBMS_DB_VERSION'
       and type = 'PACKAGE';Or even
    select dbms_metadata.get_ddl('PACKAGE', 'DBMS_DB_VERSION', 'SYS') from dual;My version is:
    SQL> select * from v$version where rownum = 1;
    BANNER                                                         
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
    1 row selectedIn 11g you also have [PL/SCOPE|http://download.oracle.com/docs/cd/E11882_01/appdev.112/e10471/adfns_plscope.htm#ADFNS02203] which might help you even more.
    Regards
    Peter

  • How Can I get all the values of a DBMS package?

    Hi all
    I'm using this "dbms_output.put_line(DBMS_DB_VERSION.VERSION || '.' ||DBMS_DB_VERSION.RELEASE);" to show the version. But how Can I get the all the values from DBMS_DB_VERSION ? Is there a common way ?
    Thanks .
    Best
    Laurence

    Hi,
    Don't think that's possible. Even if it were, you wouldn't be able to use/display BOOLEAN type in SQL.
    If you just aim to see what they are, you could do something like this
    select text
      from all_source
    where owner = 'SYS'
       and name = 'DBMS_DB_VERSION'
       and type = 'PACKAGE';Or even
    select dbms_metadata.get_ddl('PACKAGE', 'DBMS_DB_VERSION', 'SYS') from dual;My version is:
    SQL> select * from v$version where rownum = 1;
    BANNER                                                         
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
    1 row selectedIn 11g you also have [PL/SCOPE|http://download.oracle.com/docs/cd/E11882_01/appdev.112/e10471/adfns_plscope.htm#ADFNS02203] which might help you even more.
    Regards
    Peter

  • Problem with Checkbox in JTable

    This table here displays data from my MS Access database. It has 3 columns. Also I added the 4th column where this column contains checkboxes where I can select any row from the table. The checkboxes won't show except this "javax.swing.JCheckBox[,0,0,0x0,invalid,alignmentX=0.0,alignmentY=0.5,border=javax.swing.plaf.BorderUIResource$CompoundBorderUIResource@1571886,flags=296,maximumSize=,minimumSize=,preferredSize=,defaultIcon=,disabledIcon=,disabledSelectedIcon=,margin=javax.swing.plaf.InsetsUIResource[top=2,left=2,bottom=2,right=2],paintBorder=false,paintFocus=true,pressedIcon=,rolloverEnabled=true,rolloverIcon=,rolloverSelectedIcon=,selectedIcon=,text=]". I have no problem displaying the table. Here's my coding.
    public Contact() {
    super(new GridLayout(1,0));
    Vector heading = new Vector();
              heading.addElement("Name");
              heading.addElement("Contact number");
              heading.addElement("Detail");
              heading.addElement(new JCheckBox(););
              Vector data = new Vector();
    try
    // Load the Database Driver Class
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    System.out.println("Driver loaded successfully.");
    // Establish a connection with parameter values for
    // database connection URL, username, password
    Connection con =
    DriverManager.getConnection("jdbc:odbc:db1","","");
    System.out.println("Connection established successfully.");
    try
    // Create a statement
    Statement stmt = con.createStatement();
    System.out.println("Statement created successfully.");
    String sql = "SELECT * FROM Contact";
    String[] columnNames = {"Name", "Contact Number", "Detail"};
    ResultSet rs = stmt.executeQuery(sql);
    System.out.println("SQL Query executed successfully.");
    System.out.println("Output the data from the result set");
    while (rs.next())
    Vector row = new Vector();
    row.addElement(rs.getString("Name"));
    row.addElement(rs.getString("Contact number"));
    row.addElement(rs.getString("Detail"));
    row.addElement(new JCheckBox());
    data.addElement(row);
    System.out.println("Output Completed.");
              rs.close();
    stmt.close();
    finally
    con.close();
    catch (Exception e)
    e.printStackTrace();
    final JTable table = new JTable(data, heading);
    table.setPreferredScrollableViewportSize(new Dimension(500, 500));
    table.setFillsViewportHeight(true);
    JScrollPane scrollPane = new JScrollPane(table);
    add(scrollPane);
    Where have I gone wrong? Please help.

    First of all:
    a) Don't forget to use the "Code Formatting Tags", so the posted code retains its original formatting.
    http://forum.java.sun.com/help.jspa?sec=formatting
    b) In the future, Swing related questions should be posted in the Swing forum.
    Now for the answer to your question, read the JTable API. You will find a link to the Swing tutorial on "How to Use Tables" which shows you the proper way to display Boolean data with a JCheckBox renderer.

  • ADF Faces - af:tree - updating nodeStamp components

    My tree's nodeStamp is an af:selectBooleanCheckbox which maps to a hierarchy of items of indeterminate depth. There are usually at least 3 levels however. If I toggle a parent checkbox then all the child checkboxes must also toggle to match. That is the whole point of the parents in this tree is to be able to turn on or off sets of children, grand-children etc. This should be a pretty standard thing to do with trees. However, I have a bit of a dilemma and I'm hoping that someone out there can help me.
    When I toggle a parent checkbox the ThemeTree.valueChangeListener does a getModel().getRowData() to return the current row. I can then traverse the model tree from that instance to toggle all the children to match the state of the parent. From the model perspective everything works fine.
    However, if the tree is expanded when the parent state is changed, the visual state of the children do not change! The parent Checkbox is unchecked but the child Checkboxes remain checked :(or visa versa):
    Now to make things even more weird. If I close the parent tree and reopen it the children remain out of sync with the parent; even though the backing code model data is properly set.
    Even weirder. If the parent Checkbox is not expanded and I change the state and then I open the parent all the child Checkboxes are CORRRECTLY set.
    My jsp code looks as follows.
    <af:panelGroup partialTriggers="theme_display">
    <af:tree id="theme_tree" var="theme"
           binding="#{ThemeTree.tree}"
           value="#{ThemeTree.model}"
           partialTriggers="theme_display">
    <f:facet name="nodeStamp">
      <af:panelGroup layout="horizontal">
        <af:objectImage source="#{theme.graphic}"
                        rendered="#{theme.graphic != null}"
                        align="right"/>
        <af:objectSpacer width="3"
                         rendered="#{theme.graphic != null}"/>
        <af:selectBooleanCheckbox id="theme_tree_row"
                                  value="#{theme.display}"
                                  text="#{theme.displayName}"
                                  shortDesc="#{theme.shortDesc}"
                                  autoSubmit="true" immediate="true"
                                  valueChangeListener="#{ThemeTree.valueChangeListener}"/>
      </af:panelGroup>
    </f:facet>
    </af:tree>
    ....My ValueChangeListener looks like this.
        public void valueChangeListener(ValueChangeEvent vce) {
            if (tree != null) {
                setTreeChangeHappening(true);
                ThemeTreeBean currentTheme = (ThemeTreeBean)treeModel.getRowData();
                if (currentTheme.getChild() != null) {
                    boolean display = ((Boolean)vce.getNewValue()).booleanValue();
                    currentTheme.setDisplayAll(display);
                //TODO: is this doing what I think it is doing?  I'm starting to think not.
                AdfFacesContext afc = AdfFacesContext.getCurrentInstance();
                UIComponent checkBox = vce.getComponent();
                String id = checkBox.getId();
                int i = treeModel.getRowIndex();
                while (treeModel.isRowAvailable()) {
                    ThemeTreeBean themeBean = (ThemeTreeBean)treeModel.getRowData();
                    String x = themeBean.getName(); // used for debugging
                    String y = themeBean.getDisplayName(); // used for debuggin
                    afc.addPartialTarget(checkBox); // this might do something if we could get the instance of the UIComponent from the treeModel
                    afc.partialUpdateNotify(checkBox);
                    treeModel.setRowIndex(++i);
        }List of things that I've tried
    (a) I know how to AdfFacesContext.getCurrentInstance().addPartialTarget(vce.getComponent()) and ...partialUpdateNotify(same) but I haven't figured out how to get a handle on the UIComponent instances of the child Checkboxes. The components inside a nodeStamp facet seem to live an arms-length existance. I tried binding the selectBooleanCheckbox to a CoreSelectBooleanCheckbox property in my var class (theme) but this just doesn't work: ADF does not appear to allow it.
    (b) I tried various combinations using partialTriggers (no luck there).
    (c) The id cannot be a JSF expression (even though the JDeveloper tip claims it can; the ADF documentation says no) so I cannot get the id to find the UIComponent of the children. (Are there UIComponents of the children?)
    (d) I tried traversing the treeModel using the setRowIndex(int) method but this only stepped me through the parent level, it did no return the children. Even if it did I'm not sure how I would force the visual update of the child.
    The long and short of it is that the behaviour of components inside the nodeStamp is different and it makes for a real problem. I'm about to abandon the af:tree and see if there is anything in myfaces that might help. But before I give up altogether, I thought that I'd ask one more time to see if anyone out there could give me a hint for anything else to try.
    Thanks in advance, Mark

    More information: You cannot use the var attribute to bind the SelectBooleanCheckbox because it is not a managed bean and you can only bind to managed beans. So I created a CoreSelectBooleanCheckbox property in the ThemeTreeTree class (which is a managed bean) with the intent of matching references to the checkBox property as it rippled through the list.
    BUT...it doesn't ripple through the list. There is only one instance of the CoreSelectBooleanCheckbox which appears to be shared by all the visible components.
    So ... I'm still stumped.

  • Problem with synchronisation

    i have created an applet with two buttons and have brought in concept of threads
    and when i click one button a thread starts and it starts printing
    the numbers and if i press another button another
    thread starts and it also start printing
    but my requirement is when i press the button
    until the printing by one thread is completed even
    when other button is pressed it should not start printing.
    i tried doing it by synchronsing the particular method which does
    the printing but still pressing the other button also bought the numbers
    in the picture
    can anybody tell me why is this that even after synchronizing is done for that method the pressing of other button starts printing...
    The code is given below
    public class Thread_ex extends Applet implements ActionListener{
         public Canvas display;
         boolean kd =true;
         public Thread_ex() throws HeadlessException {
              super();
         Counter k;
         Counter k1;
         int i=0;
         * @param args
         public void init()
              /* Make on/off buttons for threads */
                   Button a = new Button("ON/OFF 1");
                   add(a);
                   Button b = new Button("ON/OFF 1");
                   add(b);
                   a.addActionListener(new Thread_ex() );
                   b.addActionListener(new Thread_ex() );
              public void actionPerformed(ActionEvent arg0) {
                   // TODO Auto-generated method stub
                   k = new Counter();
                   k.start();
    public class Counter extends Thread {
    //private volatile int x =0;
         public Counter() {
              super();
              // TODO Auto-generated constructor stub
         public void run()
              set();
         public synchronized void set(){
              int i=0 ;
              while(i<50)
              long currentTimeMillis = System.currentTimeMillis();
              long changeTime = 0;
              while((System.currentTimeMillis() - currentTimeMillis) <= 1000){
              //changeTime = ;
              //     System.out.println(System.currentTimeMillis());
              System.out.println(i);
              i++;
    }

    You are creating new instances of Counter and they are all syncrhonizing on themselves.
    Either synchronize the set() method internally on Counter.class, or change Counter to a Runnable of which there is only one instance, and start a new Thread with that as the Runnable every button press, and leave the set() method alone.

  • Configuring a subVI to have a configuration window/dialog box

    I am attempting to write my own slope/y-intercept calibration subVI for a program I'm building into an executable to be used on another machine.  The program is a generic DAQ program and I want the user to have some control over the calibration of the incoming signals.
    My questions are these:
    how can I configure the subVI to have a boolean input that when asserted will open that particular subVI's Front Panel.  I would also like to have a "Close" or "Cancel" button that closes that front panel once the user has changed those values.
    am I using the Configuration Data sub vis properly?  It seems pretty obvious.  I would like there to be a "config.cfg" file created/openned/written to in the base folder of my final executable.  Can multiple instances of this subvi use the same file?  I assume so, because there are "section" inputs for the writting and reading Configuation Data subVIs
    Inputs:
    (bool) Open Front Panel
    (string) Instance Label (wired to the "section" inputs for the writting and reading configuration data subvis).
    (dbl) Input (x)
    Output:
    (dbl) output (y)
    Thank you for your help.
    -Nic

    Your problems isn't really with the config VIs but rather your VI's architecture. It sounds like you want this VI to be used as a subVI that simply gives you "output" when you set a "display" boolean input to False. If the boolean input is set to True then the subVI should display itself allowing the user to click the buttons. Well, your subVI's architecture needs to change. You need to have a case structure that will run only if the "display" is True. The code to execute in this case should be a simple event structure. See attached example as a suggested alternative.
    Attachments:
    linear_calibration mod.vi ‏29 KB

  • Check box in Grid for multiple selection

    Hi,
    Right now i am using dynamic code to generate grid for checkboxs(multiple selection) it is working fine but it is taking time to generate grid.Is there any method(MII 12.0 option) to display data along in the gird
    Thanks
    Ramesh

    In MII 12.2 we added the "checkbox" display option/feature for the MII iGrid applet for displaying boolean values using the checkbox icon.  If you want something more robust and interactive the iGrid may not be the best choice and leveraging an XSLT to generate HTML dynamically from your XML data , HTML 5 libraries, or dHTMLx can all be options for supporting more robust UI displays. 
    Perhaps this link will help you along with understanding the XSLT route:
    Interfacing MII and the dHTMLx Editable Grid  The following document will discuss in detail how to create a working interface from the dHTMLx Editable Grid to MII Query Templates. It also includes a sample project with a working example and content to illustrate how this interface can be achieved.
    Sam
    PS: Please remember that the MII UI is intended to be a mash-up design so just about any web technology will work...I say just about because .aspx will not as there isn't a .NET backed for NetWeaver.

  • Application freezes when "started"

    Here is the complete source for a countdown timer (i.e., a stopwatch).
    The code compiles, but the program freezes whenever the user presses "start". The timer doesn't count down, either. The four levels of while loops in the `updateTextArea' function could very well contain the problem, but I'm not sure.
    Also: The sloppy programming `updateTextArea' is a partial consequence of my not being allowed to use timekeeping utilities, other than a `Timer' object.
    No "timeElapsed = someJavaUtility.timeNow - someJavaUtility.timeAtSomeReferenceTime" or anything like that.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class CountdownTimer extends JPanel {
            public static void main(String[] args) {
                    JFrame f = new JFrame("Countdown Timer");
                     CountdownTimer content = new CountdownTimer();
                    f.setContentPane(content);
                    f.setSize(72 * 6, 72 * 3); // 6" x 3"
                    f.setLocation(400, 100);
                    f.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE );
                    f.setVisible(true);
                    f.setResizable(false);
            } // End main()
            JButton startButton, stopButton, resetButton, exitButton;
            JTextField display;
            JLabel message;
            JCheckBox hmToggle; // Toggles between hh:* and mmmm:* display.
            public CountdownTimer() {
                    setBackground(Color.GRAY);
                    setLayout( new FlowLayout(FlowLayout.LEFT, 10, 10) );
                    TimeKeeper timeKeeper = new TimeKeeper();
                    display = new JTextField("00:00:00.00");
                    message = new JLabel("");
                    add(display);
                    add(message);
                    add(timeKeeper);
                    add(hmToggle);
             * Instances of this class hold the time remaining on the timer.
            private static class HMS {
                    static final int
                            MINUTES = 1,  // Display time remaining as mmmm:ss
                            HOURS   = 10; // Display time remaining as hh:mm:ss
                    int hours;
                    int minutes;
                    int seconds;
                    // This variable holds TEN TIMES the number of milliseconds remaining.
                    int msec;
            private class ConstructDisplay extends HMS {
                    String displayHours = hours + ":" + minutes + ":" + seconds + "." + msec;
                    String displayMinutes = minutes + ":" + seconds + "." + msec;
            private class Action implements ActionListener {
                    public void actionPerformed(ActionEvent evt) { };
            private class TimeKeeper extends JPanel {
                            String timeEntered;             // Time entered in the display.
                            boolean minutesMode = false;    // Display mmmm:ss ?
                            HMS timeLeft;                   // Time remaining.
                            ConstructDisplay timerDisplay;  // Displays...
                            Timer timer;                    // Timer object.
                            public TimeKeeper() {
                                    setLayout(new FlowLayout(FlowLayout.LEFT) );
                                    startButton = new JButton("Start");
                                    stopButton = new JButton("Stop");
                                    resetButton = new JButton("Reset");
                                    exitButton = new JButton("Exit");
                                    hmToggle = new JCheckBox("Display Minutes and Seconds");
                                    // Set up listening
                                    startButton.addActionListener( new ActionListener() {
                                            public void actionPerformed(ActionEvent evt) {
                                                    start();
                                    stopButton.addActionListener(new Action() );
                                    resetButton.addActionListener(new Action());
                                    exitButton.addActionListener(new Action());
                                    hmToggle.addActionListener(new Action());
                                    // Add buttons to (sub-)panel
                                    add(startButton);
                                    add(stopButton);
                                    add(resetButton);
                                    add(exitButton);
                                    ActionListener action = new ActionListener() {
                                            public void actionPerformed(ActionEvent evt) {
                                            Object source = evt.getSource();
                                                   if(hmToggle == source) {
                                                   // Monitors the state of the
                                                   // checkbox.
                                                   minutesMode = true;
                                            countDown();
                                    timer = new Timer(10, action);
                                    // On launch:
                                    stopButton.setEnabled(false);
                                    resetButton.setEnabled(false);
                            } // End constructor
                            public void paintComponent(Graphics g) {
                                    super.paintComponent(g);
                             * Parse the display string, and start the timer.
                            private void start() {
                                    if(timeLeft == null) {
                                            timeLeft = new HMS();
                                            timerDisplay = new ConstructDisplay();
                                    // Disable interaction with the display while the
                                    // timer is counting down.
                                    display.setEditable(false);
                                    timeEntered = display.getText();
                                    // Fill the `timeLeft' record.
                                    timeLeft.hours   = Integer.parseInt( timeEntered.substring(0, 1) );
                                    timeLeft.minutes = Integer.parseInt( timeEntered.substring(3, 4) );
                                    timeLeft.seconds = Integer.parseInt( timeEntered.substring(6, 7) );
                                    timeLeft.msec    = Integer.parseInt( timeEntered.substring(9, 10) );
                                    if(minutesMode) {
                                            timeLeft.minutes = Integer.parseInt( timeEntered.substring(0, 3) );
                                            timeLeft.seconds = Integer.parseInt( timeEntered.substring(5, 6) );
                                            timeLeft.msec    = Integer.parseInt( timeEntered.substring(8, 9) );
                                    timer.start();
                            } // End start()
                             * Count down, 10 ms at a time. The display is updated
                             * based on the presentation selected by the user before clicking
                             * `start'.
                            private void countDown() {
                                    updateTextArea(timeLeft, HMS.HOURS);
                                    if(minutesMode) updateTextArea(timeLeft, HMS.MINUTES);
                                    // Update a warning indicator (future release).
                             * Stops, but does not reset, the timer. Allows the user to
                             * pause (for breaks, for example).
                            private void stop() {
                                    timer.stop();
                             * Resets the timer, which must be stopped before the
                             * display is reset.
                            private void reset() {
                                    stop();
                                    display.setText("00:00:00.00");
                                    if(minutesMode) display.setText("0000:00.00");
                                    timeLeft = null;
                             * Exits the program. (to avoid a possible namespace violation,
                             * the name `exit()' was not used).
                            private void exitTimer() {
                                    System.exit(0);
                             * Called to alert the user that time is up.
                            private void timeIsUp() {
                                    stop();
                                    message.setText("Time's up!");
                             * Updates the display after each "tick" of the timer. The
                             * display used is dependent upon the user's preference.
                            private void updateTextArea(HMS timeLeft, int displayType) {
                                    if(displayType == HMS.HOURS) {
                                    while(timeLeft.hours >= 0) {
                                            while(timeLeft.minutes >= 0) {
                                                    while(timeLeft.seconds >= 0) {
                                                            while(timeLeft.msec >= 0) {
                                                                    if(timeLeft.hours == 0 && timeLeft.minutes == 0 && timeLeft.seconds == 0 && timeLeft.msec == 0)
                                                                            timeIsUp();
                                                                    timeLeft.msec--;
                                                                    display.setText(timerDisplay.displayHours);
                                                                    if(timeLeft.msec == 0) {
                                                                            timeLeft.msec = 99;
                                                                            timeLeft.seconds--;
                                                                    repaint();
                                                             } // End `ms' block
                                                             if(timeLeft.seconds == 0) {
                                                                    timeLeft.seconds = 59;
                                                                    timeLeft.minutes--;
                                                    } // End `s' block
                                                    if(timeLeft.minutes == 0) {
                                                          timeLeft.minutes = 59;
                                                          timeLeft.hours--;
                                            } // End `m' block
                                    } // End `h' block
                                    } // end if
                                    // This is definitely cruft and will need to be cleaned up....
                                    if(displayType == HMS.MINUTES) {
                                            while(timeLeft.minutes >= 0) {
                                                    while(timeLeft.seconds >= 0) {
                                                            while(timeLeft.msec >= 0) {
                                                                    if(timeLeft.minutes == 0 && timeLeft.seconds == 0 && timeLeft.msec == 0)
                                                                            timeIsUp();
                                                                    timeLeft.msec--;
                                                                    display.setText(timerDisplay.displayMinutes);
                                                                    if(timeLeft.msec == 0) {
                                                                            timeLeft.msec = 99;
                                                                            timeLeft.seconds--;
                                                                    repaint();
                                                             } // End `ms' block
                                                             if(timeLeft.seconds == 0) {
                                                                    timeLeft.seconds = 59;
                                                                    timeLeft.minutes--;
                                                    } // End `s' block
                                            } // End `m' block
                                    } // end if
                            } // End updateTextArea()
            } // End nested class TimeKeeper
    }// End class CountdownTimer

    I would suggest you rethink the approach to use a Swing Timer or a Thread for your countdown timer, i will post a short example of a
    countdown timer using a swing timer. This countdown will update every second, but if you need to really accurate use a thread, all those nested whiles are scary, view Swing Timer api here:
    http://java.sun.com/javase/6/docs/api/javax/swing/Timer.html
    or Thread Here:
    http://java.sun.com/javase/6/docs/api/java/lang/Thread.html
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    //Implement ActionListener in order to use a Swing Timer
    public class SimpleTimer extends JFrame implements ActionListener{
         int time = 0;
         Timer timer; //Swing Timer
         JPanel display;
         public SimpleTimer(String s, int t){
              super(s);
              time= t;
              //Create a swing timer Timer(delay, ActionListener)
              timer = new Timer(1000, this);
                    //Start the timer (This is the real advantage ofa swing timer hte start() and stop methods())
                    //You may be using a button to do this or some other event but for simplicity i'm just starting it here
              timer.start();
              //display is used to show the time, i'm using paint but you could just as easily use a label or textbox etc...
              display = new JPanel(){
                   public void paintComponent(Graphics g){
                        super.paintComponent(g);
                        g.drawString(time + "", 5, 20);
              getContentPane().add(display);
              setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
              setSize(300, 300);
              setVisible(true);
         //Is called by the Swing Timer
         public void actionPerformed(ActionEvent e){
              if (time == 0)
                   timer.stop();
              else{
                   time -= 1;
                   repaint(); //Called because i used paintComponent(Graphics g), could be JLabel.setText(String s), blah blah blah
         public static void main(String[] args){
              SimpleTimer st = new SimpleTimer("Simple Timer", 100);
    }

  • Urgent!!! please give me some advice

    i quite new in J2ME programming. i encountered a problem that my MIDlet cannot pass parameter to servlet. i had tried to not using os.flush(), but it's still not working. please give me some suggestion!
    MIDlet
    * Login.java
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.io.Connector;
    import javax.microedition.io.HttpConnection;
    import javax.microedition.io.StreamConnection;
    import java.io.DataOutputStream;
    import java.io.DataInputStream;
    import java.io.InputStream;
    import java.io.OutputStream;
    import java.io.IOException;
    import java.util.*;
    public class Login extends MIDlet implements CommandListener {
    Display display;
    boolean commandAvailable;
    // String idPassword;
    CommandThread commandThread;
    Form inputForm;
    Form outputForm;
    TextField userid;
    TextField password;
    StringItem response;
    Command cmdExit;
    Command cmdOK;
    public void startApp() {
    display = Display.getDisplay(this);
    inputForm = new Form("Authorization");
    userid = new TextField("User",null,25, TextField.ANY);
    inputForm.append(userid);
    password = new TextField("Password",null, 15, TextField.PASSWORD);
    inputForm.append(password);
    cmdOK = new Command("OK",Command.SCREEN,1);
    cmdExit = new Command("Exit",Command.EXIT,1);
    inputForm.addCommand(cmdOK);
    inputForm.addCommand(cmdExit);
    inputForm.setCommandListener(this);
    outputForm = new Form("Student Option");
    response = new StringItem(null,null);
    outputForm.append(response);
    outputForm.addCommand(cmdExit);
    outputForm.setCommandListener(this);
    commandAvailable = false;
    commandThread = new CommandThread(this);
    commandThread.start();
    display.setCurrent(inputForm);
    public void pauseApp() {
    public void destroyApp(boolean unconditional) {
    public void commandAction(Command cmd, Displayable d) {
         if (cmd == cmdExit) {
    destroyApp(false);
    notifyDestroyed();
    else if (cmd == cmdOK)
    synchronized (this) {
    commandAvailable = true;
    notify();
    class CommandThread extends Thread {
    MIDlet parent;
    boolean exit = false;
    public CommandThread(MIDlet parent) {
    this.parent = parent;
    public void run() {
    while (true) {
    synchronized(parent) {
    while(!commandAvailable) {
    try {
    parent.wait();
    catch (InterruptedException e) {
    commandAvailable = false;
    performLogin();
    public void performLogin() {
    HttpConnection conn = null;
    InputStream is = null;
    OutputStream os = null;
    byte[] receivedData = null;
    try {
    String url = getAppProperty("Login.URL");
    conn = (HttpConnection)Connector.open(url);
         byte[] postData = createPostData();
    conn.setRequestMethod(HttpConnection.POST);
    conn.setRequestProperty("User-Agent", "Profile/MIDP-1.0 Configuration/CLDC-1.0");
    conn.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
         conn.setRequestProperty ( "Content-Length", Integer.toString (postData.length));
    // conn.setRequestProperty("Accept", "application/octet-stream" );
    conn.setRequestProperty("Connection", "close" );
    // byte[] postData = createPostData();
    System.out.println("postData="+postData);
    conn.setRequestProperty("Content-length",Integer.toString(postData.length));
         os = conn.openOutputStream();
         os.write(postData);
    for (int i=0;i<postData.length;i++)
              os.write(postData);
    //     os.flush();
         os.close();
         is = conn.openInputStream();
         String contentType = conn.getType();
    int len = (int)conn.getLength();
    if (len > 0) {
    receivedData = new byte[len];
    int nb = is.read(receivedData);
    else {
    receivedData = new byte[1024];
    int ch;
    len = 0;
    while ((ch = is.read()) != -1) {
    receivedData[len++] = (byte)ch;
    response.setText(new String(receivedData,0,len));
    display.setCurrent(outputForm);
    catch (IOException e) {
    System.out.println(e.getMessage());
    e.printStackTrace();
    finally {
    try {
    if (is != null) {
    is.close();
    if (os != null) {
    os.close();
    if (conn != null) {
    conn.close();
    catch (IOException e) {
    public byte[] createPostData() {
    StringBuffer sb = new StringBuffer();
    sb.append("userid=");
    sb.append(userid.getString());
    sb.append("&password=");
    sb.append(password.getString());
    System.out.println("sb = <" + sb.toString() + ">");
    return sb.toString().getBytes();
    servlet
    import java.io.*;
    import java.text.*;
    import java.util.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.sql.*;
    public class LoginServlet extends HttpServlet {
    static final String dbURL = "jdbc:mysql://localhost/projectdb?" + "user=wongyuenmei&password=wongyuenmei";
    public void doPost(HttpServletRequest request,HttpServletResponse response) throws IOException, ServletException {
    Connection conn = null;
    String nextJSP = null;
    try {
    Class.forName("org.gjt.mm.mysql.Driver");
    catch (ClassNotFoundException e) {
    throw new ServletException("Unable to load JDBC driver");
    try {
    String id = request.getParameter("userid").trim();
    String pass = request.getParameter("password").trim();
         if (id==null)
    String tempid=id;
    String temppass=pass;
    conn = DriverManager.getConnection(dbURL);
    Statement stmt = conn.createStatement();
    String query = "SELECT cno, idno " + "FROM student " + "WHERE idno = '" + id + "'AND password ='" + pass + "'";
    ResultSet rs = stmt.executeQuery(query);
    if (rs.next()) {
    StringBuffer fullName = new StringBuffer();
    fullName.append(rs.getString(1));
    fullName.append(" ");
    fullName.append(rs.getString(2));
    request.setAttribute ("fullName", fullName.toString());
    nextJSP = "/LoginOK.jsp";
    else {
         StringBuffer temptest = new StringBuffer();
         temptest.append(tempid);
         temptest.append(&temppass);
         request.setAttribute("temptest", temptest.toString());
    nextJSP = "/LoginFailed.jsp";
    conn.close();
    ServletConfig config = getServletConfig();
    ServletContext context = config.getServletContext();
    RequestDispatcher rd = context.getRequestDispatcher(nextJSP);
    rd.forward(request, response);
    catch (SQLException e) {
    throw new ServletException("SQL call failed");
    catch (Exception e) {
    throw new ServletException(e.getMessage());
    finally {
    if (conn != null) {
    try {
    conn.close();
    catch (SQLException e) {
    throw new ServletException("connection close failed");
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
    doPost(request, response);
    ur help is very appreciated!

    Still the same problem. All the parameter get by server are null.
    Using GET, and add parameter to url, everything is fine.
    encodedPostData = "E2EE_PAM_ID"+"="+E2EE_PAM_ID+"&"+"E2EE_USER_ID"+"=" E2EE_USER_ID"&"+"E2EE_USER_SEGUID"+"="+E2EE_USER_SEGUID+"&"+"E2EE_RPIN"+"="+E2EE_RPIN
    +"&LoginBtn=Login";
    c = (HttpConnection)Connector.open(request);
    c.setRequestMethod(HttpConnection.POST);
    c.setRequestProperty("User-Agent","Profile/MIDP-1.0 Configuration/CLDC-1.0");
    c.setRequestProperty("Content-Type:","application/x-www-form-urlencoded");
    os = c.openOutputStream();
    os.write(encodedPostData.getBytes());
    //os.flush();
    System.out.println(encodedPostData);
    rc = c.getResponseCode();
    if (rc != HttpConnection.HTTP_OK) {
    throw new IOException("HTTP response code: " + rc);
    is = c.openInputStream();
    ..........

  • Problems with swing, please help!!!

    im trying to display an image made up of a set of squares.
    i have a JFrame class which has the main method placing a JComponent into its Container using the getContentPane().add method.
    the JComponent class sets up the image using the paintComponent() method
    When i try to run the program all i get is a grey frame.
    Ive looked at other threads in this forum to fix my problem but it doesnt seem to fix it.
    any help is much appreciated.

    import java.awt.*;
    import java.awt.event.*;
    import java.util.EventListener;
    import javax.swing.*;
    import java.applet.*;
    public class Display extends JFrame
         protected DisCanvas canvas;
         protected EventListener listener;
         protected boolean isApplet = false;
         public Display(boolean isApplet)
              this.isApplet = isApplet;
              //setLayout(new BorderLayout());
         //     add(makeCanvas(), BorderLayout.CENTER);
         public Display()
              //this(true);
    canvas = new DisCanvas();
    this.getContentPane().setLayout(new BorderLayout());
    this.getContentPane().add(canvas, BorderLayout.CENTER);
    this.addWindowListener(new AppCloser());
    this.setSize(300, 300);
    this.setVisible(true);
    this.repaint();
    public static void main(String[] args)
    new Display();
    static class AppCloser extends WindowAdapter
              public void windowClosing(WindowEvent e)
                   System.exit(0);
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.awt.image.*;
    public class DisCanvas extends java.awt.Canvas
    Patch[] patchArray = new Patch[100];
    int width = 200;
    int height = 300;
    BufferedImage image;
    Graphics2D g2D;
    public DisCanvas()
    patchArray[0] = new Patch(0, 0, 20, 30); patchArray[10] = new Patch(0, 30, 20, 30);
    patchArray[1] = new Patch(20, 0, 20, 30); patchArray[11] = new Patch(20, 30, 20, 30);
    patchArray[2] = new Patch(40, 0, 20, 30); patchArray[12] = new Patch(40, 30, 20, 30);
    patchArray[3] = new Patch(60, 0, 20, 30); patchArray[13] = new Patch(60, 30, 20, 30);
    patchArray[4] = new Patch(80, 0, 20, 30); patchArray[14] = new Patch(80, 30, 20, 30);
    patchArray[5] = new Patch(100, 0, 20, 30); patchArray[15] = new Patch(100, 30, 20, 30);
    patchArray[6] = new Patch(120, 0, 20, 30); patchArray[16] = new Patch(120, 30, 20, 30);
    patchArray[7] = new Patch(140, 0, 20, 30); patchArray[17] = new Patch(140, 30, 20, 30);
    patchArray[8] = new Patch(160, 0, 20, 30); patchArray[18] = new Patch(160, 30, 20, 30);
    patchArray[9] = new Patch(180, 0, 20, 30); patchArray[19] = new Patch(180, 30, 20, 30);
    patchArray[20] = new Patch(0, 60, 20, 30); patchArray[30] = new Patch(0, 90, 20, 30);
    patchArray[21] = new Patch(20, 60, 20, 30); patchArray[31] = new Patch(20, 90, 20, 30);
    patchArray[22] = new Patch(40, 60, 20, 30); patchArray[32] = new Patch(40, 90, 20, 30);
    patchArray[23] = new Patch(60, 60, 20, 30); patchArray[33] = new Patch(60, 90, 20, 30);
    patchArray[24] = new Patch(80, 60, 20, 30); patchArray[34] = new Patch(80, 90, 20, 30);
    patchArray[25] = new Patch(100, 60, 20, 30); patchArray[35] = new Patch(100, 90, 20, 30);
    patchArray[26] = new Patch(120, 60, 20, 30); patchArray[36] = new Patch(120, 90, 20, 30);
    patchArray[27] = new Patch(140, 60, 20, 30); patchArray[37] = new Patch(140, 90, 20, 30);
    patchArray[28] = new Patch(160, 60, 20, 30); patchArray[38] = new Patch(160, 90, 20, 30);
    patchArray[29] = new Patch(180, 60, 20, 30); patchArray[39] = new Patch(180, 90, 20, 30);
    patchArray[40] = new Patch(0, 120, 20, 30); patchArray[50] = new Patch(0, 150, 20, 30);
    patchArray[41] = new Patch(20, 120, 20, 30); patchArray[51] = new Patch(20, 150, 20, 30);
    patchArray[42] = new Patch(40, 120, 20, 30); patchArray[52] = new Patch(40, 150, 20, 30);
    patchArray[43] = new Patch(60, 120, 20, 30); patchArray[53] = new Patch(60, 150, 20, 30);
    patchArray[44] = new Patch(80, 120, 20, 30); patchArray[54] = new Patch(80, 150, 20, 30);
    patchArray[45] = new Patch(100, 120, 20, 30); patchArray[55] = new Patch(100, 150, 20, 30);
    patchArray[46] = new Patch(120, 120, 20, 30); patchArray[56] = new Patch(120, 150, 20, 30);
    patchArray[47] = new Patch(140, 120, 20, 30); patchArray[57] = new Patch(140, 150, 20, 30);
    patchArray[48] = new Patch(160, 120, 20, 30); patchArray[58] = new Patch(160, 150, 20, 30);
    patchArray[49] = new Patch(180, 120, 20, 30); patchArray[59] = new Patch(180, 150, 20, 30);
    patchArray[60] = new Patch(0, 180, 20, 30); patchArray[70] = new Patch(0, 210, 20, 30);
    patchArray[61] = new Patch(20, 180, 20, 30); patchArray[71] = new Patch(20, 210, 20, 30);
    patchArray[62] = new Patch(40, 180, 20, 30); patchArray[72] = new Patch(40, 210, 20, 30);
    patchArray[63] = new Patch(60, 180, 20, 30); patchArray[73] = new Patch(60, 210, 20, 30);
    patchArray[64] = new Patch(80, 180, 20, 30); patchArray[74] = new Patch(80, 210, 20, 30);
    patchArray[65] = new Patch(100, 180, 20, 30); patchArray[75] = new Patch(100, 210, 20, 30);
    patchArray[66] = new Patch(120, 180, 20, 30); patchArray[76] = new Patch(120, 210, 20, 30);
    patchArray[67] = new Patch(140, 180, 20, 30); patchArray[77] = new Patch(140, 210, 20, 30);
    patchArray[68] = new Patch(160, 180, 20, 30); patchArray[78] = new Patch(160, 210, 20, 30);
    patchArray[69] = new Patch(180, 180, 20, 30); patchArray[79] = new Patch(180, 210, 20, 30);
    patchArray[80] = new Patch(0, 240, 20, 30); patchArray[90] = new Patch(0, 270, 20, 30);
    patchArray[81] = new Patch(20, 240, 20, 30); patchArray[91] = new Patch(20, 270, 20, 30);
    patchArray[82] = new Patch(40, 240, 20, 30); patchArray[92] = new Patch(40, 270, 20, 30);
    patchArray[83] = new Patch(60, 240, 20, 30); patchArray[93] = new Patch(60, 270, 20, 30);
    patchArray[84] = new Patch(80, 240, 20, 30); patchArray[94] = new Patch(80, 270, 20, 30);
    patchArray[85] = new Patch(100, 240, 20, 30); patchArray[95] = new Patch(100, 270, 20, 30);
    patchArray[86] = new Patch(120, 240, 20, 30); patchArray[96] = new Patch(120, 270, 20, 30);
    patchArray[87] = new Patch(140, 240, 20, 30); patchArray[97] = new Patch(140, 270, 20, 30);
    patchArray[88] = new Patch(160, 240, 20, 30); patchArray[98] = new Patch(160, 270, 20, 30);
    patchArray[89] = new Patch(180, 240, 20, 30); patchArray[99] = new Patch(180, 270, 20, 30);
    image = new BufferedImage(width, height,BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2D = image.createGraphics();
    public void paint/*Component*/(Graphics g)
    g = (Graphics2D) g2D;
    super.paint/*Component*/(g);
    for (int i = 0; i == 99; i++)
    //for (int s = 0; s > 5; s++)
    // Color[] colours = new Color[6];
    // colours[0] = Color.blue;
    // colours[1] = Color.red;
    // colours[2] = Color.green;
    // colours[3] = Color.orange;
    // colours[4] = Color.black;
    // colours[5] = Color.white;
    // g2D.setColor(colours[s]);
    g2D.setColor(Color.red);
    g2D.fillRect(patchArray.getX(), patchArray[i].getY(),
    patchArray[i].getWidth(), patchArray[i].getHeight());
    g2D.drawImage(image,0, 0, this);

  • Changing backgroundin JTable

    I have a JTable wich display boolean. I want to change the background color depending on wich column i am. I tried using my own class extending DefaultCellRenderer but i remove "the checkbox" style of all the cells.
    Any ideas of keeping the checkbox style and setting the bakground the color i want.
    Thanks

    myTable.getTableHeader().getColumnModel().getColumn(0).setHeaderValue("Foo");

Maybe you are looking for