Java 数据库未通过JSF更新

Java 数据库未通过JSF更新,java,mysql,jsf,jsf-2,Java,Mysql,Jsf,Jsf 2,我正在使用JSF更新数据库,但当我按下按钮后检查数据库时,信息不在那里。我连接不正确吗?另外,我有4个按钮,1个更新数据库,1个查看数据库,1个插入数据库,1个清除表单。这些方法应该在信息bean中,还是应该都有自己的bean?谢谢你们 index.html <?xml version='1.0' encoding='UTF-8' ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

我正在使用JSF更新数据库,但当我按下按钮后检查数据库时,信息不在那里。我连接不正确吗?另外,我有4个按钮,1个更新数据库,1个查看数据库,1个插入数据库,1个清除表单。这些方法应该在信息bean中,还是应该都有自己的bean?谢谢你们

index.html

    <?xml version='1.0' encoding='UTF-8' ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"

 <h:head>
    <title>Staff Information</title>
</h:head>
<h:body>
    <font size="10"> Staff Information </font>
    <h:form>

        <div style="height:30px">
            <h:outputLabel value="ID:  "/>
            <h:inputText id="ID"
                         value="#{information.ID}"/>
        </div>

        <div style="height:30px">
            <h:outputLabel value="Last Name  " />
            <h:inputText id="lastName"
                         value="#{information.lastName}"/>

            <h:outputLabel value="    First Name  " />
            <h:inputText id="firstName"
                         value="#{information.firstName}"/>

            <h:outputLabel value=" MI  "/>
            <h:inputText id="middle"
                         value="#{information.middle}"/>
        </div>

        <div style="height:30px">
            <h:outputLabel value="Address  "/>
            <h:inputText id="address"
                         value="#{information.address}"/>
        </div>

        <div style="height:30px">
            <h:outputLabel value="City   "/>
            <h:inputText id="city" 
                         value="#{information.city}"/>

            <h:outputLabel value="State  "/>
            <h:inputText id="state" 
                         value="#{information.state}"/>
        </div>

        <div style="height:30px">
            <h:outputLabel value="Telephone # "/>
            <h:inputText id="phone"
                         value="#{information.phone}"/>
        </div>

        <h:commandButton value="View"/> 
        <h:outputText value="&#160;" />

        <h:commandButton value="Insert"/>
        <h:outputText value="&#160;" />

        <h:commandButton value="Update" action="#{information.add()}"/>

        <h:outputText value="&#160;" />

        <h:commandButton type="reset" value="Clear" />
        <h:outputText value="&#160;" />

        </h:form>
    </h:body>
</html>
视图类

public void view(){
    try{
     Class.forName("com.mysql.jdbc.Driver");
     System.out.println("Driver loaded");

     Connection connect = DriverManager.getConnection("jdbc:mysql://"
             + "localhost:3306/Staff");
     System.out.println("Database connected");

     String sql = "SELECT * FROM Staff WHERE id="+id;

     System.out.println(sql);

    }
   catch (ClassNotFoundException | SQLException e)
    {
        System.out.println(e);
    }
}
视图类的html

<h:commandButton value="View"> 
            <f:param name="action" value="#{information.view()}" />
        </h:commandButton>


请进入调试,看看它是否真的来了,并在插入数据的地方执行你的文章。你在服务器控制台或浏览器控制台中看到任何类型的错误吗?@LearningPhase I没有错误。你能确认你的方法add是通过调试器调用的吗?在Add方法的开头添加一些系统输出,然后看到outputI为view按钮创建了一个类,其中包含一些print语句,因为它似乎是最容易调试的。我把它加起来。
<h:commandButton value="View"> 
            <f:param name="action" value="#{information.view()}" />
        </h:commandButton>