0

您好,我尝试进行数据库操作。

这是我的豆子

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

// Import Statements
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.annotation.ManagedBean;


@ManagedBean
public class DatabaseOperation {

    static final String DbDriver = "com.mysql.jdbc.Driver";  // To set the driver
    static final String strConnection = "jdbc:mysql://localhost:3306/TekirMobile"; // Connection string 
    static final String strDbUsername = "root"; // Username of the database user
    static final String strDbPassword = "fenderpass"; // Password of the database user
    static Connection DatabaseConnection; // Connection object to establish the connection to the database
    static ResultSet RsStudent; // Resultset to store the information retrieved from the database
    static Statement DatabaseStatement; // Statement object of the database connection
    String beginDate;

    public DatabaseOperation() // Constructor of the class
    {
        makeConnection(); // To establish the database connection
    }

    public void makeConnection() // To establish the database connection, No return value and parameters
    {
        try {
            Class.forName(DbDriver); // Setting the driver

            DatabaseConnection = DriverManager.getConnection(strConnection, strDbUsername, strDbPassword); // Establishing the connection with the database

            DatabaseStatement = DatabaseConnection.createStatement(); // Assigning the statement to the connection
            System.out.println("Connection Success....");
        } catch (Exception e) // In case of any Exception
        {
            System.out.println(e); // Print the Exception
        }
    }

    public ResultSet selectFromDatabase(String strSelectQuery) // A function which retrieves Records from the database, Returns Recordset, Query as parameter
    {
        try {
            RsStudent = DatabaseStatement.executeQuery(strSelectQuery); // Execute the select query
            return RsStudent; // Returns the resultset
        } catch (Exception e) {
            System.out.println(e); // Print the exception
            return null; // Return NULL
        }
    }

    public String submit() {
        System.out.println("Submitted value: " + beginDate);
        return null;
    }

    public void disConnect() {
        try {
            DatabaseConnection.close();
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        // TODO Auto-generated method stub

    }
}

这是我的 jsf

  <h:panelGroup>
  <h:outputLabel id="beginDate" value="Begin Date:" /><br />
  <h:inputText value="#{DatabaseOperation.beginDate}" style="width:95%;"  />
  </h:panelGroup>

这也是我的按钮

  <h:panelGroup>
  <h:commandButton type="submit" action="#{DatabaseOperation.submit}"  />
  </h:panelGroup>

当我按下按钮时,我得到这个错误为什么?怎么了?我需要做什么吗?我的豆子对吗?我发送到价值豆?

4

1 回答 1

0

我认为当您尝试从 JSF 页面访问您的 bean 时,第一个字母应该更低:

<h:panelGroup>
    <h:commandButton type="submit" action="#{databaseOperation.submit}"  />
</h:panelGroup>

您还可以像这样设置名称:

@ManagedBean(name="databaseOperation")
于 2013-03-24T14:18:49.907 回答