Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/374.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java MenuBar.Command()在Vaadin中不显示任何结果_Java_Mysql_Menubar_Vaadin7 - Fatal编程技术网

Java MenuBar.Command()在Vaadin中不显示任何结果

Java MenuBar.Command()在Vaadin中不显示任何结果,java,mysql,menubar,vaadin7,Java,Mysql,Menubar,Vaadin7,通过从MySQL数据库中检索值,检查其中一个字段是否为true,然后相应地将菜单项添加到菜单栏中,从而动态创建菜单栏,菜单栏得到了正确的实现。但是,当我选择任何菜单项并尝试打印所选项的检索文本时,它不会打印任何内容 我的UI类:(Project3UI.java) 我的视图类:(MemberStudentView.java) 它只是打印 Connecting to Database... Creating statement... Goodbye! 并且在控制台上不打印其他内容 我是Vaadin

通过从MySQL数据库中检索值,检查其中一个字段是否为true,然后相应地将菜单项添加到菜单栏中,从而动态创建菜单栏,菜单栏得到了正确的实现。但是,当我选择任何菜单项并尝试打印所选项的检索文本时,它不会打印任何内容

我的UI类:(Project3UI.java)

我的视图类:(MemberStudentView.java)

它只是打印

Connecting to Database...
Creating statement...
Goodbye!
并且在控制台上不打印其他内容


我是Vaadin的新手。

你希望它打印什么?@peant:我希望它打印菜单中未打印的选定项的文本。。我已经在上面提到过。。请看。
package com.example.project3;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import com.vaadin.annotations.Theme;
import com.vaadin.navigator.Navigator;
import com.vaadin.navigator.View;
import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
import com.vaadin.server.ThemeResource;
import com.vaadin.ui.Embedded;
import com.vaadin.ui.Label;
import com.vaadin.ui.Layout;
import com.vaadin.ui.MenuBar;
import com.vaadin.ui.Panel;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.MenuBar.MenuItem;

@Theme("mytheme1")
public class MemberStudentView extends Panel implements View {

    static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";  
    static final String DB_URL = "jdbc:mysql://localhost/ClubPortalDb";

    //  Database credentials
    static final String USER = "xxxx";
    static final String PASS = "xxxxx";
    Navigator navigator;
    Connection conn = null;
    Statement stmt = null;
    String cname;
    String status;


     public MemberStudentView() {
            super(new VerticalLayout());
            setCaption("Messages");
            Embedded e = new Embedded();
            e.setSource(new ThemeResource("img/club1.PNG"));
            MenuBar menubar = new MenuBar();
            menubar.setWidth("100%");
            MenuItem Clubs = menubar.addItem("MY CLUBS",null,null);
            MenuItem PendingClubs = menubar.addItem("PENDING REQUESTS", null, null);
            ((Layout)getContent()).addComponent(e);
            ((Layout)getContent()).addComponent(menubar);

            try{
                  //STEP 2: Register JDBC driver
                  Class.forName("com.mysql.jdbc.Driver");

                  //STEP 3: Open a connection
                  System.out.println("Connecting to database...");
                  conn = DriverManager.getConnection(DB_URL,USER,PASS);

                  //STEP 4: Execute a query
                  System.out.println("Creating statement...");
                  stmt = conn.createStatement();
                  String sql;
                  sql = "Select * from memberStudent WHERE name = 'Priya'";
                  ResultSet rs = stmt.executeQuery(sql);
                  while(rs.next()){
                      cname = rs.getString("ClubName");
                      status = rs.getString("membership_status");
                      if(status.equalsIgnoreCase("true")){
                          Clubs.addItem(cname, null, null);  
                      }
                      else if(status.equalsIgnoreCase("false")){
                          PendingClubs.addItem(cname, null, null);  
                      }

                  }
                  rs.close();
                  stmt.close();
                  conn.close();
               }catch(SQLException se){
                  //Handle errors for JDBC
                  se.printStackTrace();
               }catch(Exception e2){
                  //Handle errors for Class.forName
                  e2.printStackTrace();
               }
               System.out.println("Goodbye!");
               MenuBar.Command mycommand = new MenuBar.Command() {
                     public void menuSelected(MenuItem selectedItem) {
                         System.out.println(selectedItem.getText());
                          if(selectedItem.getText().equalsIgnoreCase(cname.toLowerCase()))
                        {
                            System.out.println("cmnm");  
                        }

                          else if(selectedItem.getText().equals("PENDING REQUESTS"))
                        { 
                              System.out.println("cmnp"); 
                        }

                        };
                };

       }
    @Override
    public void enter(ViewChangeEvent event) {
           navigator  = event.getNavigator();
    }



}
Connecting to Database...
Creating statement...
Goodbye!