Results 1 to 3 of 3
  1. #1
    aborgeld is offline Senior Member
    Join Date
    Dec 2010
    Location
    The Hague
    Posts
    114
    Rep Power
    0

    Default Making more than one reports to screen with list

    I making one list i can use in different cases, which can take more than one output query and thats why i want
    to make my own to string method.


    The code:
    And this is the most important code of this list, in the controller package:
    Java Code:
      public void fillList2(Object[] objecten) {
        this.dbObjecten = objecten;
    
        ArrayList<String> fillList2 = new ArrayList<String>();
        for (int i=0; i < objecten.length; i++) {
          fillList2.add(uitl.toString2());
        }
        this.list.setListData(fillList2.toArray());
       
      }
    One model class with
    2 queries

    Java Code:
      public static Uitleen[] getAllUitleningen() {
        return getUitleenRs(          "select      a.uitleen_id," +
                                                    "a.uitleen_uitleendatum, "+
                                                    "a.uitleen_vervaldatum, "+
                                                    "a.uitleen_terugbrengdatum, "+
                                                    "a.uitleen_bijzonderheden, "+
                                                    "a.uitleen_boete, "+
                                                    "a.lid_nummer, "+
                                                    "b.lid_voorletters, "+
                                                    "b.lid_achternaam, "+
                                                    "a.speelgoed_code, "+
                                                    "c.speelgoed_omschrijving "+
                                     "from          uitleen as a "+
                                                    "join    lid as b "+
                                     "on            a.lid_nummer = b.lid_nummer "+
                                     "join          speelgoed as c "+
                                     "on            a.speelgoed_code = c.speelgoed_code ");
      }
    
    
      public static Uitleen [] getUitleenSpCode(String speelgCode) {
            return getUitleenRs(   "select          a.uitleen_id, "+
                                                    "a.uitleen_uitleendatum, "+
                                                    "a.uitleen_vervaldatum, "+
                                                    "a.uitleen_terugbrengdatum, "+
                                                    "a.uitleen_bijzonderheden, "+
                                                    "a.uitleen_boete, "+
                                                    "a.lid_nummer, "+
                                                    "b.lid_voorletters, "+
                                                    "b.lid_achternaam, "+
                                                    "a.speelgoed_code, "+
                                                    "c.speelgoed_omschrijving "+
                                     "from          uitleen as a "+
                                     "join          lid as b "+
                                     "on            a.lid_nummer = b.lid_nummer "+
                                     "join          speelgoed as c "+
                                     "on            a.speelgoed_code = c.speelgoed_code "+
                                     "where         a.speelgoed_code LIKE'%" + speelgCode + "%'");
    
    
       }


    Java Code:
     private static Uitleen[] getUitleenRs(String query) {
             ResultSet r = Database.executeSelectQuery(query);
    
    
            int aantalUitleningen = Database.getAmountResultSet(r);
            Uitleen[] uitleningen = new Uitleen[aantalUitleningen];
    
            try {
    
                int teller  = 0;
                while (teller < aantalUitleningen) {
    
                    Uitleen value = new Uitleen();
                    value.speelgCode = r.getString("speelgoed_code");
                    value.omschrijving = r.getString("speelgoed_omschrijving");
                    value.uitleenDatum = r.getString("uitleen_uitleendatum");
                    value.uitleenVervaldatum = r.getString("uitleen_vervaldatum");
                    value.uitleenTerugbrengDatum = r.getString("uitleen_terugbrengdatum");
                    value.uitleenBijzonderheden = r.getString("uitleen_bijzonderheden");
                    value.uitleenBoete = r.getString("uitleen_boete");
                    value.lidNummer = r.getString("lid_nummer");
                    value.lidVoorletters = r.getString("lid_voorletters");
                    value.lidAchternaam = r.getString("lid_achternaam");
    
                    uitleningen[teller] = value;
                    teller++;
                    r.next();
                }
           }
    
         catch (SQLException e) {
          System.out.println("Uitleen: getUitleenSp: " + e.toString());
          System.out.println(e.getMessage() + "\n" + e.getSQLState() + "\n" + e.getErrorCode());
        }
        return uitleningen;
      }
    My own toString method because i need one more toString method for the second query.

    Java Code:
    public  String  toString2() {
    
    
             String value  = "";
              value += JSqlList.setSpaces(getCode().toString(), 8);
               value += JSqlList.setSpaces(getOmschrijving().toString(), 12);
               value += JSqlList.setSpaces(getUitleenDatum().toString(), 18);
               value += JSqlList.setSpaces(getUitleenVervaldatum().toString(), 18);
               value += JSqlList.setSpaces(getUitleenTerugbrengDatum().toString(), 18);
               value += JSqlList.setSpaces(getUitleenBijzonderheden(), 20);
               value += JSqlList.setSpaces(getUitleenBoete().toString(), 30);
               value += JSqlList.setSpaces(getLidNummer().toString(), 5);
               value += JSqlList.setSpaces(getLidVoorletters().toString(), 5);
               value += JSqlList.setSpaces(getLidAchternaam().toString(), 18);
           
    
    
           return value;
      
        }
    At last the view where i call my list:
    Java Code:
     uitleenLijst.fillList2(uitl.getUitleenSpCode(speelgCode));
    Last edited by aborgeld; 01-16-2011 at 11:11 PM.

  2. #2
    aborgeld is offline Senior Member
    Join Date
    Dec 2010
    Location
    The Hague
    Posts
    114
    Rep Power
    0

    Default

    I get a nullpointer exception. I think it begins at my own ToString method: value.speelgCode = r.getString("speelgoed_code");
    Can anybody please have a look at what i'm doing wrong.


    run:
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at model.Uitleen.toString2(Uitleen.java:358)
    at componenten.JSqlList.fillList2(JSqlList.java:44)
    at view.UitleningenPerSpeelgoed.<init>(UitleningenPer Speelgoed.java:29)
    at view.Overzichten.uitlPerSpeelgoedButtonActionPerfo rmed(Overzichten.java:84)
    at view.Overzichten.access$000(Overzichten.java:18)
    at view.Overzichten$1.actionPerformed(Overzichten.jav a:43)
    at javax.swing.AbstractButton.fireActionPerformed(Abs tractButton.java:1995)
    at javax.swing.AbstractButton$Handler.actionPerformed (AbstractButton.java:2318)
    at javax.swing.DefaultButtonModel.fireActionPerformed (DefaultButtonModel.java:387)
    at javax.swing.DefaultButtonModel.setPressed(DefaultB uttonModel.java:242)
    at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(BasicButtonListener.java:236)
    at java.awt.Component.processMouseEvent(Component.jav a:6267)
    at javax.swing.JComponent.processMouseEvent(JComponen t.java:3267)
    at java.awt.Component.processEvent(Component.java:603 2)
    at java.awt.Container.processEvent(Container.java:204 1)
    at java.awt.Component.dispatchEventImpl(Component.jav a:4630)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2099)
    at java.awt.Component.dispatchEvent(Component.java:44 60)
    at java.awt.LightweightDispatcher.retargetMouseEvent( Container.java:4577)
    at java.awt.LightweightDispatcher.processMouseEvent(C ontainer.java:4238)
    at java.awt.LightweightDispatcher.dispatchEvent(Conta iner.java:4168)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2085)
    at java.awt.Window.dispatchEventImpl(Window.java:2478 )
    at java.awt.Component.dispatchEvent(Component.java:44 60)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java: 599)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:269)
    at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:184)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:174)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:169)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:161)
    at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:122)
    BUILD SUCCESSFUL (total time: 6 seconds)
    Last edited by aborgeld; 01-16-2011 at 11:13 PM.

  3. #3
    aborgeld is offline Senior Member
    Join Date
    Dec 2010
    Location
    The Hague
    Posts
    114
    Rep Power
    0

    Default

    With the code in this post (standard) and standard overriding ToString it works, but only with one query. I want to show it on screen like a report in one window.
    But i need two queries and thats why i want to use my own toString, so i can create a ToString1 and ToString2 with different fields to set from the database
    Java Code:
      
    private Object[] dbObjecten;
    
     public void fillList(Object[] objecten) {
        this.dbObjecten = objecten;
    
        ArrayList<String> fillList = new ArrayList<String>();
        for (Object o : dbObjecten) {
          fillList.add(o.toString());      
        }
        this.list.setListData(fillList.toArray());
      }

Similar Threads

  1. What to use for Pdf reports?
    By hari.kr in forum Advanced Java
    Replies: 2
    Last Post: 04-29-2010, 11:15 AM
  2. Replies: 0
    Last Post: 12-29-2009, 03:10 PM
  3. Blank Screen while navigating from one screen to another
    By mohana.krishna in forum Java Servlet
    Replies: 0
    Last Post: 03-03-2009, 05:03 PM
  4. [SOLVED] Making a list in java.
    By VinTiger in forum New To Java
    Replies: 18
    Last Post: 02-16-2009, 12:41 AM
  5. Jasper Reports
    By sunjavaboy in forum Advanced Java
    Replies: 0
    Last Post: 10-28-2008, 09:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •