Target unreachable,identifier'DatabaseOperation'resolved resolved to null

问题描述:

你好,我尝试做一个数据库操作。Target unreachable,identifier'DatabaseOperation'resolved resolved to null

这是我的豆

/* 
* 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> 

当我按下按钮,我得到这个错误,为什么?出了什么问题?我需要做什么?我的豆子是对的吗?我发送给bean的价值吗?

我觉得第一个字母应该是较低的,当你尝试从JSF页面访问你的bean:

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

您还可以设置名字是这样的:

@ManagedBean(name="databaseOperation") 
+0

仍然没有工作。 – user2153566 2013-03-24 14:20:23

+0

尝试像上面那样设置名称。当你尝试设置上面的名字时会发生什么?日志在服务器启动时会说什么吗?显然这个bean不能解决。 – Magnilex 2013-03-24 14:22:20

+0

nop。我是否需要将我的bean添加到某个地方?任何地方都是.xml? – user2153566 2013-03-24 14:22:53