How to prevent number duplication in Java.

How do i prevent number duplication in this program. Basically so that i don't have to enter the same number again
here's the code:
import java.awt.*;
import hsa.Console;
public class BubbleSort_Strings
    static Console c;           // The output console
    public static void main (String[] args)
        c = new Console ();
        c.println ("\t\t\tIPOD Downloads\n\n");
        c.print ("Enter the number of songs: ");
        int max = c.readInt ();
        c.println ();
        String song[] = new String [max];
        String tempSong;
        for (int i = 0 ; i <= max - 1 ; i = i + 1)
            c.print ("Enter the name of song " + (i + 1) + ": ");
            song = c.readLine ();
c.println ();
} //end for i
//sort the song names in the array alphabetically
for (int x = 0 ; x < max - 1 ; x++)
for (int y = x + 1 ; y < max ; y++)
if (song [x].compareTo (song [y]) > 0)
tempSong = song [x];
song [x] = song [y];
song [y] = tempSong;
} //end if
} //end for y
} //end for x
c.println ("Your songs have now been sorted:");
c.println ();
for (int z = 0 ; z <= max - 1 ; z = z + 1)
c.println (song [z]);
} //end for z
} // main method
} // BubbleSort_Strings class

here how about this:
// The "BubbleSort_Numbers" class.
import java.awt.*;
import hsa.Console;
public class BubbleSort_Numbers
    static Console c;           // The output console
    public static void main (String[] args)
        c = new Console ();
        c.print ("Enter the number of items: ");
        int max = c.readInt();
        int item[] = new int [max];
        int temp;
        for (int i = 0 ; i <= max - 1 ; i = i + 1)
            c.print ("Enter a number for the array: ");
            item = c.readInt ();
} //end for i
for (int x = 0 ; x < max - 1 ; x++)
for (int y = x + 1 ; y < max ; y++)
if (item [x] < item [y])
temp = item [x];
item [x] = item [y];
item [y] = temp;
} //end if
} //end for y
} //end for x
c.println ("The numbers have been sorted.");
for (int z = 0 ; z <= max - 1 ; z = z + 1)
c.println (item [z]);
} //end for z
} // main method
} // BubbleSort_Numbers class

Similar Messages

  • How to prevent unicode conversion in Java?

    Hi all,
    There are some existing Chinese characters stored in our RDBMS using charset=IBMPC850. The text can correctly be displayed using a window GUI developed by Visual C++ by declaring the field as DBCS. However, when I tried to retrieve the Chinese field back using JDBC and JSP. The words are distorted. I suspect that Java converts all string to unicode and no matter what encoding I tried to change when viewing my page, I still don't get the Chinese words correctly.
    On the other hand, if I enter Chinese characters through my JSP, I can read them back correctly using:
    resultSet.getString
    Does anyone have any ideas about this?
    Your help is greatly appreciated!
    Thanks in advance.

    My guess is that you need to tell your JDBC driver which encoding to use when talking to the database server. I don't know which DBMS or driver you use so I can't help you with that. :-(
    A workaround could be to manually convert the strings after they have been retrieved from the server, using some code like this:
    String s = resultset.getString(...);
    s = new String(s.getBytes(), "Big5");
    That should do the trick if the JDBC driver reads the characters using the default (in Java) encoding, and if the database is encoded in Big5 (I don't think it's encoded in IBM code page 850 since that is an 8-bit encoding used in western Europe).
    Good luck!
    Jesper

  • Preventing IDoc duplication

    Hi,
    Not sure if this question applies to this forum or if it applies to application server issue but we have 1 receiver SAP ECC and 2 SAP ECC senders of same IDocs because we have connected 2 different systems having same data for test purposes. When both the sender systems send the same data and post as IDoc in receiver system, it causes duplication of IDocs with double records. We are using XI as the middle component between the sending and receiving systems.
    My question is, is there any way to prevent this from duplicating the IDocs in receiving system? or What is the best way or how to prevent this duplication of IDocs? Is there a standard function module or BAPI to do this check? Or is there any way to prevent this in XI or sending systems? Does anyone have any other ideas that has worked in this situation?
    Thanks,
    Sangita

    >
    Sangita S wrote:
    > Hi,
    >
    > Not sure if this question applies to this forum or if it applies to application server issue but we have 1 receiver SAP ECC and 2 SAP ECC senders of same IDocs because we have connected 2 different systems having same data for test purposes. When both the sender systems send the same data and post as IDoc in receiver system, it causes duplication of IDocs with double records. We are using XI as the middle component between the sending and receiving systems.
    >
    > My question is, is there any way to prevent this from duplicating the IDocs in receiving system? or What is the best way or how to prevent this duplication of IDocs? Is there a standard function module or BAPI to do this check? Or is there any way to prevent this in XI or sending systems? Does anyone have any other ideas that has worked in this situation?
    >
    > Thanks,
    > Sangita
    OK , let me sum up your case ,
    You have 2 sender systems , which sends the IDOCS
    you have 1 receiver system , which receives the IDOC via XI.
    Now due to some reason both sender system creates exactly the same IDOC ( which may be correct from technology point of view ) but I do not see valid business reason for that, anyway it seems just an odd scenario , but the issue is you want to filter out of those 2 similar IDOCS only 1 should go to Target system.
    If my understanding is correct of above scenario, XI will not be able to distinguish between these 2 IDOCS as duplicate,unless
    You use BPM to collect the IDOCs and remove duplicates before pushing it to Receiver system. This solution may seem too much of a work which is just bcos of testing systems.
    So easiest way would be to remove the business reason as why both system are triggering the IDOCs or they may be completely valid.
    Thanks,

  • How to prevent duplication on a column with condition

    Hello everyone,
    I need some advice here. At work, we have an Oracle APEX app that allow user to add new records with the automatic increment decision number based on year and group name.
    Says if they add the first record , group name AA, for year 2012, they get decision number AA 1 2013 as their displayed record casein the report page.
    The second record of AA in 2013 will be AA 2 2013.
    If they add about 20 records , it will be AA 20 2013.
    The first record for 2014 will be AA 1 2014.
    However, recently , we get a user complaint about two records from the same group name have the same decision number.
    When I looked into the history table, and find that the time gap between 2 record is just about 0.1 seconds.
    Besides, we have lookup table that allows admin user to update the Start Sequence number with the restraint that it has to be larger than the max number of the current group name of the current year.
    This Start sequence number and group name is stored together in a table.
    And in some other special case,user can add a duplicate decision number for related record. (this is a new function)
    The current procedure logic to add new record on the application are
    _Get max(decision_number) from record table with chosen Group Name and current year.
    _insert into the record table the new entered record with decision number + 1
    _ update sequence number to the just added decision number.
    So rather than utitlising APEX built-in automatic table modification process, I write a procedure that combine all the three process.
    I run some for loop to continuously execute this procedure, and it seems it can autotically generate new unique decision number with time gap about 0.1 second.
    However, when I increase the number of entry to 200, and let two users run 100 each.
    If the time gap is about 0.01 second, Duplicate decision numbers appear.
    What can I do to prevent the duplication ?
    I cannot just apply a unique constraint here even for all three columns with condition, as it can have duplicate value in some special condition. I don't know much about using lock and its impact.
    This is the content of my procedure
    create or replace
    PROCEDURE        add_new_case(
      --ID just use the trigger
      p_case_title IN varchar2,
      p_year IN varchar2,
      p_group_name IN VARCHAR2,
      --decisionnumber here
      p_case_file_number IN VARCHAR2,
      --active
      p_user IN VARCHAR2
    AS
      default_value NUMBER;
        caseCount NUMBER;
      seqNumber NUMBER;
      previousDecisionNumber NUMBER;
    BEGIN
      --execute immediate q'[alter session set nls_date_format='dd/mm/yyyy']';
      SELECT count(*)
            INTO caseCount
            FROM CASE_RECORD
            WHERE GROUP_ABBR = p_group_name
            AND to_number(to_char(create_date, 'yyyy')) = to_number(to_char(date_utils.get_current_date, 'yyyy'));
            SELECT max(decision_number)
            INTO previousDecisionNumber
            FROM CASE_RECORD
            WHERE GROUP_ABBR = p_group_name
            AND to_number(to_char(create_date, 'yyyy')) = to_number(to_char(date_utils.get_current_date, 'yyyy'));
            IF p_group_name IS NULL
            THEN seqNumber := 0;
            ELSE   
            SELECT seq_number INTO seqNumber FROM GROUP_LOOKUP WHERE ABBREVATION = p_group_name;
            END IF;
        IF caseCount > 0 THEN
               default_value := greatest(seqNumber, previousdecisionnumber)+1;
        ELSE
               default_value := 1;
        END IF; 
      INSERT INTO CASE_RECORD(case_title, decision_year, GROUP_ABBR, decision_number, case_file_number, active_yn, created_by, create_date)
      VALUES(p_case_title, p_year, p_group_name, default_value, p_case_file_number, 'Y', p_user, sysdate );
      --Need to update sequence here also
      UPDATE GROUP_LOOKUP
      SET SEQ_NUMBER = default_value
      WHERE ABBREVATION = p_group_name;
      COMMIT;
    EXCEPTION
    WHEN OTHERS THEN
        logger.error(p_message_text => SQLERRM
                    ,p_message_code => SQLCODE
                    ,p_stack_trace  => dbms_utility.format_error_backtrace
        RAISE;
    END;
    Many thanks in advance,
    Ann

    Why not using a sequence for populating the decision_number column ?
    Sequence values are guaranteed to be unique so there's no need to lock anything.
    You'll inevitably have gaps and no different groups will have the same decision_number in common.
    Having to deal with consecutive numbers fixations you can proceed as
    with
    case_record as
    (select 2012 decision_year,'AA' group_abbr,1 decision_number from dual union all
    select 2012,'BB',2 from dual union all
    select 2012,'AA',21 from dual union all
    select 2012,'AA',22 from dual union all
    select 2012,'BB',25 from dual union all
    select 2013,'CC',33 from dual union all
    select 2013,'CC',34 from dual union all
    select 2013,'CC',36 from dual union all
    select 2013,'BB',37 from dual union all
    select 2013,'AA',38 from dual union all
    select 2013,'AA',39 from dual union all
    select 2013,'BB',41 from dual union all
    select 2013,'AA',42 from dual union all
    select 2013,'AA',43 from dual union all
    select 2013,'BB',45 from dual
    select decision_year,
           group_abbr,
           row_number() over (partition by decision_year,group_abbr order by decision_number) decision_number,
           decision_number sequence_number -- not shown (noone needs to know you're using a sequence)
      from case_record
    order by decision_year,group_abbr,decision_number
    DECISION_YEAR
    GROUP_ABBR
    DECISION_NUMBER
    SEQUENCE_NUMBER
    2012
    AA
    1
    1
    2012
    AA
    2
    21
    2012
    AA
    3
    22
    2012
    BB
    1
    2
    2012
    BB
    2
    25
    2013
    AA
    1
    38
    2013
    AA
    2
    39
    2013
    AA
    3
    42
    2013
    AA
    4
    43
    2013
    BB
    1
    37
    2013
    BB
    2
    41
    2013
    BB
    3
    45
    2013
    CC
    1
    33
    2013
    CC
    2
    34
    2013
    CC
    3
    36
    for retrieval (assuming decision_year,group_abbr,decision_number as being the key):
    select decision_year,group_abbr,decision_number -- the rest of columns
      from (select decision_year,
                   group_abbr,
    -- the rest of columns
                   row_number() over (partition by decision_year,group_abbr order by decision_number) decision_number
              from case_record
             where decision_year = :decision_year
               and group_abbr = :group_abbr
    where decision_number = :decision_number
    DECISION_YEAR
    GROUP_ABBR
    DECISION_NUMBER
    2013
    AA
    4
    if that's acceptable
    Regards
    Etbin

  • Hello , FMS is how to prevent the client into a large number of bytes?

    Hello , FMS how to prevent the client to pass a large number of bytes , such as one person put a 1G file in the argument , I also silly to receive ?Although there Client.setBandwidthLimit ( ) limit his maximum traffic per second , but is there a way , one more than the maximum amount of bytes to disconnect his.I assume that methods to determine the length is also obtained all of his transfer is finished , in order to determine out of it .

    How to limit the size of the parameters of the method.I wrote a method in the main.asc then the client NetConnection.call assignment, but if the client is malicious to upload very large data, how to limit it, I view the document did not find the clues, I hope that those parameters up to100KB.

  • How can prevent duplication of condition types in sales order??

    How can prevent duplication of condition types in sales order.
    While we want Amount field Changeable by user.
    Please give me solution.

    Dear Rohit,
    Can you explain your scenario in detail with an example or any screen shot so that we will help you in easy way ...
    Regards,
    C.B Reddy

  • Sequence file Version number. How to prevent the automatic resetting build version number whilst auto-incrementing revision number?

    Hi,
    I've got my environment set this way that each save of the sequence file increase the revision part of version number. However, during that increase the build counter is reset to 0. How to prevent it?
    TS 4.2

    Mimi,
    It is pretty common practice in software revisioning to reset a minor number to 0 when a major moves up 1.  There are many different schemes out there.  If you google or bing software versioning schemes you'll see what I'm talking about.
    So looking at it from left to right:  Major.Minor.Revision.Build = 0.0.0.1 
    if you change the Revision it would be expected that anything to the right (in this case Build) would reset to 0.  0.0.1.0!
    Let's say your version is 8.34.56.23.  It would make sense that if you were to change the Major number (which means a Major release) to 9 then your version would go to: 9.0.0.0. 
    A version number is just a unique way to tell someone which specific software you are using so it really doesn't matter that it resets to 0.  Although it makes sense because if you kept your build number sequential and didn't reset it then it would get outrageously larger which would be more annoying than anything. 
    Again this is common accepted practice in industry.
    Good Luck,
    jigg
    CTA, CLA
    teststandhelp.com
    ~Will work for kudos and/or BBQ~

  • How can we prevent back button  using java script

    how can we prevent back button using java script

    Would be quicker for you to google for javaScript
    javascript:window.history.forward(-1);

  • How to get number of rows return in SELECT query

    i'm very new in java, i have a question:
    - How to get number of rows return in SELECT query?
    (i use SQL Server 2000 Driver for JDBC and everything are done, i only want to know problems above)
    Thanks.

    make the result set scroll insensitve, do rs.last(), get the row num, and call rs.beforeFirst(), then you can process the result set like you currently do.
             String sql = "select * from testing";
             PreparedStatement ps =
              con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
             ResultSet rs = ps.executeQuery();
             rs.last();
             System.out.println("Row count = " + rs.getRow());
             rs.beforeFirst();~Tim
    NOTE: Ugly, but does the trick.

  • How to find number of files in a folder using pl/sql

    please someone guide as to how to find number of files in a folder using pl/sql
    Regards

    The Java option works well.
    -- results table that will contain a file list result
    create global temporary table directory_list
            directory       varchar2(1000),
            filename        varchar2(1000)
    on commit preserve rows
    -- allowing public access to this temp table
    grant select, update, insert, delete on directory_list to public;
    create or replace public synonym directory_list for directory_list;
    -- creating the java proc that does the file listing
    create or replace and compile java source named "ListFiles" as
    import java.io.*;
    import java.sql.*;
    public class ListFiles
            public static void getList(String directory, String filter)
            throws SQLException
                    File path = new File( directory );
                    final String ExpressionFilter =  filter;
                    FilenameFilter fileFilter = new FilenameFilter() {
                            public boolean accept(File dir, String name) {
                                    if(name.equalsIgnoreCase(ExpressionFilter))
                                            return true;
                                    if(name.matches("." + ExpressionFilter))
                                            return true;
                                    return false;
                    String[] list = path.list(fileFilter);
                    String element;
                    for(int i = 0; i < list.length; i++)
                            element = list;
    #sql {
    insert
    into directory_list
    ( directory, filename )
    values
    ( :directory, :element )
    -- creating the PL/SQL wrapper for the java proc
    create or replace procedure ListFiles( cDirectory in varchar2, cFilter in varchar2 )
    as language java
    name 'ListFiles.getList( java.lang.String, java.lang.String )';
    -- punching a hole in the Java VM that allows access to the server's file
    -- systems from inside the Oracle JVM (these also allows executing command
    -- line and external programs)
    -- NOTE: this hole MUST be secured using proper Oracle security (e.g. AUTHID
    -- DEFINER PL/SQL code that is trusted)
    declare
    SCHEMA varchar2(30) := USER;
    begin
    dbms_java.grant_permission(
    SCHEMA,
    'SYS:java.io.FilePermission',
    '<<ALL FILES>>',
    'execute, read, write, delete'
    dbms_java.grant_permission(
    SCHEMA,
    'SYS:java.lang.RuntimePermission',
    'writeFileDescriptor',
    dbms_java.grant_permission(
    SCHEMA,
    'SYS:java.lang.RuntimePermission',
    'readFileDescriptor',
    commit;
    end;
    To use:
    SQL> exec ListFiles('/tmp', '*.log' );
    PL/SQL procedure successfully completed.
    SQL> select * from directory_list;
    DIRECTORY FILENAME
    /tmp X11_newfonts.log
    /tmp ipv6agt.crashlog
    /tmp dtappint.log
    /tmp Core.sd-log
    /tmp core_intg.sd-log
    /tmp da.sd-log
    /tmp dhcpclient.log
    /tmp oracle8.sd-log
    /tmp cc.sd-log
    /tmp oms.log
    /tmp OmniBack.sd-log
    /tmp DPISInstall.sd-log
    12 rows selected.
    SQL>

  • Bank Account number duplication in IT0009

    Dear Team,
    We want to stop the Bank Account number duplication in IT0009.
    This is regarding the updating the Infotype 0009 for a personnel number in PA30. While updating a bank account number for any employee, system has to check whether the same bank account number is updated in the database for any other employee or not so that we can stop updating the same account number to different employees.
    Please let me know how to address this.
    Kind Regards
    Nag

    Hi Nag,
    You can use the following code in the include ZXPADU02.
    DATA: v_bankn TYPE bankn.
    CASE innnn-infty.
      WHEN '0009'.
        SELECT SINGLE bankn FROM pa0009
          INTO v_bankn
         WHERE bankn = innnn-data1+113(18).
        IF sy-subrc = 0.
          MESSAGE 'Bank Account is already assigned' TYPE 'E'.
        ENDIF.
    ENDCASE.
    Pradeep.

  • How to prevent JFileChooser automatically changing to parent directory?

    When you show only directories, and click on the dir icons to navigate, and then dont select anything and click OK, it automatically 'cd's to the parent folder.
    My application is using the JFileChooser to let the user navigate through folders and certain details of 'foo' files in that folder are displayed in another panel.
    So we dont want the chooser automatically changing dir to parent when OK is clicked. How to prevent this behavior?
    I considered extending the chooser and looked at the Swing source code but it is hard to tell where the change dir is happening.
    thanks,
    Anil
    To demonstrate this, I took the standard JFileChooserDemo from the Sun tutorial and modified it adding these lines
              // NEW line 45 in constructor
              fc.addPropertyChangeListener((PropertyChangeListener) this);
              fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
          * NEW -
          * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
         public void propertyChange(PropertyChangeEvent e) {
              String prop = e.getPropertyName();
              if (JFileChooser.DIRECTORY_CHANGED_PROPERTY.equals(prop)) {
                   System.out.println("DIRECTORY_CHANGED_PROPERTY");
                   File file = (File) e.getNewValue();
                   System.out.println("DIRECTORY:" + file.getPath());
         }

    Here is the demo:
    package filechooser;
    import java.awt.BorderLayout;
    import java.awt.Insets;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.beans.PropertyChangeEvent;
    import java.beans.PropertyChangeListener;
    import java.io.File;
    import javax.swing.ImageIcon;
    import javax.swing.JButton;
    import javax.swing.JFileChooser;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTextArea;
    import javax.swing.SwingUtilities;
    import javax.swing.UIManager;
    * FileChooserDemo.java uses these files:
    *   images/Open16.gif
    *   images/Save16.gif
    public class FileChooserDemo extends JPanel implements ActionListener,
              PropertyChangeListener {
         static private final String newline = "\n";
         JButton openButton, saveButton;
         JTextArea log;
         JFileChooser fc;
         public FileChooserDemo() {
              super(new BorderLayout());
              // Create the log first, because the action listeners
              // need to refer to it.
              log = new JTextArea(5, 20);
              log.setMargin(new Insets(5, 5, 5, 5));
              log.setEditable(false);
              JScrollPane logScrollPane = new JScrollPane(log);
              // Create a file chooser
              fc = new JFileChooser();
              // NEW
              fc.addPropertyChangeListener((PropertyChangeListener) this);
              fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
              // Create the open button. We use the image from the JLF
              // Graphics Repository (but we extracted it from the jar).
              openButton = new JButton("Open a File...",
                        createImageIcon("images/Open16.gif"));
              openButton.addActionListener(this);
              // Create the save button. We use the image from the JLF
              // Graphics Repository (but we extracted it from the jar).
              saveButton = new JButton("Save a File...",
                        createImageIcon("images/Save16.gif"));
              saveButton.addActionListener(this);
              // For layout purposes, put the buttons in a separate panel
              JPanel buttonPanel = new JPanel(); // use FlowLayout
              buttonPanel.add(openButton);
              buttonPanel.add(saveButton);
              // Add the buttons and the log to this panel.
              add(buttonPanel, BorderLayout.PAGE_START);
              add(logScrollPane, BorderLayout.CENTER);
          * NEW -
          * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
         public void propertyChange(PropertyChangeEvent e) {
              String prop = e.getPropertyName();
              // If the directory changed, don't show an image.
              if (JFileChooser.DIRECTORY_CHANGED_PROPERTY.equals(prop)) {
                   System.out.println("DIRECTORY_CHANGED_PROPERTY");
                   File file = (File) e.getNewValue();
                   System.out.println("DIRECTORY:" + file.getPath());
         public void actionPerformed(ActionEvent e) {
              // Handle open button action.
              if (e.getSource() == openButton) {
                   int returnVal = fc.showOpenDialog(FileChooserDemo.this);
                   if (returnVal == JFileChooser.APPROVE_OPTION) {
                        File file = fc.getSelectedFile();
                        // This is where a real application would open the file.
                        log.append("Opening: " + file.getName() + "." + newline);
                   } else {
                        log.append("Open command cancelled by user." + newline);
                   log.setCaretPosition(log.getDocument().getLength());
                   // Handle save button action.
              } else if (e.getSource() == saveButton) {
                   int returnVal = fc.showSaveDialog(FileChooserDemo.this);
                   if (returnVal == JFileChooser.APPROVE_OPTION) {
                        File file = fc.getSelectedFile();
                        // This is where a real application would save the file.
                        log.append("Saving: " + file.getName() + "." + newline);
                   } else {
                        log.append("Save command cancelled by user." + newline);
                   log.setCaretPosition(log.getDocument().getLength());
         /** Returns an ImageIcon, or null if the path was invalid. */
         protected static ImageIcon createImageIcon(String path) {
              java.net.URL imgURL = FileChooserDemo.class.getResource(path);
              if (imgURL != null) {
                   return new ImageIcon(imgURL);
              } else {
                   System.err.println("Couldn't find file: " + path);
                   return null;
          * Create the GUI and show it. For thread safety, this method should be
          * invoked from the event dispatch thread.
         private static void createAndShowGUI() {
              // Create and set up the window.
              JFrame frame = new JFrame("FileChooserDemo");
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              // Add content to the window.
              frame.add(new FileChooserDemo());
              // Display the window.
              frame.pack();
              frame.setVisible(true);
         public static void main(String[] args) {
              // Schedule a job for the event dispatch thread:
              // creating and showing this application's GUI.
              SwingUtilities.invokeLater(new Runnable() {
                   public void run() {
                        // Turn off metal's use of bold fonts
                        UIManager.put("swing.boldMetal", Boolean.FALSE);
                        createAndShowGUI();
    }

  • How to prevent user from selecting a specific printer?

    Hi there
    I have a MailFolder which has an ArrayList of Email objects inside it. Each MailFolder has an attribute called folderFile which is a reference to a folder in the operating system. Each Email has an attribute called parentFile which is a reference to a file in the operating system.
    Now, I am trying to put printing into my application.
    When I print using a normal printer like my HP Deskjet or the likes - an actual physical printer - everything works fine. But when I print using the Microsoft Office Document Image Writer, things go wierd. The following things happen;
    I call myMailFolder.getFolderFile().exists() and this = false. But if I (in the debugger) make a new file pointing to the same path, .exists() = true. Also if I look in the OS, the file exists. So somehow in the job.print() this Document Image writer seems to be messing up this file reference. The same thing happens to the myEmail.getParentFile().
    So to fix this, can anyone tell me how to prevent the user from selecting this printer, or can anyone tell me why this is happening only with the Document Image Writer?
    Many thanks!
    Rachel

    I have similar problem with our printing program. I am printing Java Tables, zoom in every column in a landscape page accross multiple pages.
    There are two fatal problems:
    1. On Dell Latitude laptop, the HP5100 printer didn't work; I have to change the code to draw the table header with 2D graphics.
    2. Crash when printing on MS document image writer, but on some computers
    it works perfectly.
    Any one have a good solution/same result for topic 2?
    Thanks,

  • I need only to select node with "NodeName" (or/and Number) in a Java Tree

    I need only to select node with "NodeName" (or/and Number) in a Java Tree. Can anybody help me? Thanks a lot

    http://www.jetbrains.com/idea/openapi/5.0/com/intellij/util/ui/tree/TreeUtil.html
    http://www.tangoone.com/swf/docs/javadocs/org/swf/components/TreePane.html
    I fin SelectNode() function here - but I don't know how to connect these clases

  • How to calculate  number of sundays and saturdays between two Dates

    friends i want to calculate how many Sundays come in two Dates
    i have tried following code which is hard coded i have to impliment method which can give me number of Sundays between two Dates
    please help me
    import java.util.Date;
         import java.text.DateFormat;
         import java.text.SimpleDateFormat;
         import java.util.Calendar ;
         import java.util.GregorianCalendar;
    public class DateDiffCalculator     {
         private static final SimpleDateFormat SDF = new SimpleDateFormat("yyyy-MMM-dd");
    public DateDiffCalculator()     {
         public static Date getDate (String date) throws Exception {
    //log.debug(" "+date);
              return SDF.parse(date);
    public static Date getDate (Date date) throws Exception {
    // log.debug("date is "+date);
              return getDate(SDF.format(date));
    public static long getDiffInDays(Date d1,Date d2)     {
         boolean isdiffGreaterThanYear=false;
         long diffInMilliSeconds=d1.getTime()-d2.getTime();
         return diffInMilliSeconds/(1000*60*60*24);
    public static int getYear(String date)     {
              //String[] day=     {Sun,Mon,Tue,Wed,Thu,Fri,Sat};
              Integer     year=new     Integer(date.substring(0,4));
         return year.intValue();
    public static int getMonth(String date)     {
              //String date.substring(5,7);
              System.out.println(" "+date.substring(5,8));
              String     m= date.substring(5,8);
              int month=0;
              if(m.equalsIgnoreCase("Jan"))     {
              month=1;
              if(m.equalsIgnoreCase("Feb"))     {
              month=2;
              if(m.equalsIgnoreCase("Mar"))     {
              month=3;
              if(m.equalsIgnoreCase("Apr"))     {
              month=4;
              if(m.equalsIgnoreCase("May"))     {
              month=5;
              if(m.equalsIgnoreCase("Jun"))     {
              month=6;
              if(m.equalsIgnoreCase("Jul"))     {
              month=7;
              if(m.equalsIgnoreCase("Aug"))     {
              month=8;
              if(m.equalsIgnoreCase("Sep"))     {
              month=9;
              if(m.equalsIgnoreCase("Oct"))     {
              month=10;
              if(m.equalsIgnoreCase("Nov"))     {
              month=11;
              if(m.equalsIgnoreCase("Dec"))     {
              month=12;
              return month;
         public static int getDay(String date)     {
              Integer     day=new     Integer(date.substring(9,11));
         return day.intValue();
    public static int getNumberofSundays(String d1,String d2) throws Exception     {
              //d1 is leave start date d2 is leave end date
              // get object in Date form
                   Date date1=getDate(d1);
                   Date date2=getDate(d2);
              // now get calender objects from it
              GregorianCalendar c1= new GregorianCalendar(getYear(d1),getMonth(d1),getDay(d1));
              GregorianCalendar c2= new GregorianCalendar(getYear(d2),getMonth(d2),getDay(d2));
              // get period
              long leavePeriod = getDiffInDays(date1,date2);
         return 12; // it should return number of sundays but we type 12 to perform compilation
    public static void main(String[] arg)throws Exception     {
    System.out.println(" "+getNumberofSundays("2005-Oct-07","2006-Mar-01"));
    }

    thanks now i have modified the get Month Code
    as follows
    public static int getMonth(String date)     {
              //String date.substring(5,7);
              System.out.println(" "+date.substring(5,8));
              String     m= date.substring(5,8);
              int month=0;
              if(m.equalsIgnoreCase("Jan"))     {
              month=0;
              if(m.equalsIgnoreCase("Feb"))     {
              month=1;
              if(m.equalsIgnoreCase("Mar"))     {
              month=2;
              if(m.equalsIgnoreCase("Apr"))     {
              month=3;
              if(m.equalsIgnoreCase("May"))     {
              month=4;
              if(m.equalsIgnoreCase("Jun"))     {
              month=5;
              if(m.equalsIgnoreCase("Jul"))     {
              month=6;
              if(m.equalsIgnoreCase("Aug"))     {
              month=7;
              if(m.equalsIgnoreCase("Sep"))     {
              month=8;
              if(m.equalsIgnoreCase("Oct"))     {
              month=9;
              if(m.equalsIgnoreCase("Nov"))     {
              month=10;
              if(m.equalsIgnoreCase("Dec"))     {
              month=11;
              return month;
    but question remains same how to calculate number of Sundays Between 2 Dates

Maybe you are looking for