0

我想在标签字段中显示表格列的值(显示总量)。

这是我在开发标签时使用的代码

  Border myBorder = BorderFactory.createBitmapBorder( 
    new XYEdges(20, 16, 27, 23),
    Bitmap.getBitmapResource("border.png"));
    LabelField myField = new LabelField("Total Amount Owed: Rs ",LabelField.USE_ALL_WIDTH | LabelField.FIELD_HCENTER)
    {
      protected void paint(Graphics g) {
        g.setColor(Color.BLUE);
        super.paint(g);
    }
    };  

   myField.setBorder(myBorder);  
   add(myField); 

这是我想用来从表中获取值的 sql 语句:

 Statement statementG56 = db.createStatement("SELECT owe FROM GTemp5");
                    statementG56.prepare();
                    statementG56.execute();

如何将该选择语句包含到我的标签字段中,以便提取的数量位于标签标题旁边。

4

1 回答 1

1

这就是我实施的方式。希望对以后的读者有所帮助。

                 try
                  {
                  //Open or create the database
                    Database db = DatabaseFactory.openOrCreate("database1.db"); 

                    Statement statementGF55 = db.createStatement("CREATE TABLE IF NOT EXISTS GTemp5(owe INTEGER)");
                    statementGF55.prepare();
                    statementGF55.execute();       
                    statementGF55.close();

                    Statement statementGF56 = db.createStatement("SELECT owe FROM GTemp5");
                    statementGF56.prepare();
                    statementGF56.execute();

                   Cursor c = statementGF56.getCursor();

                  while(c.next()) 
                  {

                                      System.out.println("Inside while for fetching total owed value"); 
                                        Row r;
                                        r = c.getRow();

                                         Border myBorder = BorderFactory.createBitmapBorder( 
                                         new XYEdges(20, 16, 27, 23),
                                         Bitmap.getBitmapResource("border.png"));
                                         String pp = "" + r.getObject(0);
                                        LabelField myField = new LabelField("Total Amount: Rs    " +pp,LabelField.USE_ALL_WIDTH | LabelField.FIELD_HCENTER)
                                            {
                                                  protected void paint(Graphics g)
                                                   {
                                                     g.setColor(Color.RED);
                                                      super.paint(g);
                                                    }
                                               };  

                                   myField.setBorder(myBorder);  
                                   vfm.add(myField); 

                                    }     

                      }
                      catch(Exception e) 
                      {         
                        System.out.println( e.getMessage() );
                        e.printStackTrace();     
                      } 
于 2012-05-18T06:47:39.987 回答