Automatically populate value of inputText

37 views Asked by At

I want to retrieve a ResultSet that i retrieved from the database into an inputText in an xhtml file. Below shows the code that I've tried so far.

Profile.java

    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.util.Date;
    import com.mpts.srv.DBConnection;

    public class Profile {
        public void info(){

        String name = null;
        String mykad = null;
        String contact = null;
        Date dob = null;
        String gender = null;
        String email = null;

        DBConnection dbconn = new DBConnection("com.mysql.jdbc.Driver", "jdbc:mysql://localhost", "root",
                "root");
        dbconn.query("SELECT * FROM Patient WHERE patient_uid = SessionUtils.getUid()");
        ResultSet rs = dbconn.getResultSet();

        try {

            while (rs.next()) {

                name = rs.getString("name");
                mykad = rs.getString("mykad");
                contact = rs.getString("contact");
                dob = rs.getDate("dob");
                gender = rs.getString("gender");
                email = rs.getString("email");

            }
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        dbconn.close();
        }
    }

profile.xhtml

<h:outputLabel value="Name:"></h:outputLabel>
<b:inputText span="8" value="#{profile.getString(Name)}"></b:inputText>

How do i populate name into the inputText?

0

There are 0 answers