0

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?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • I think you should take a step back and start with some more basic tutorials. Looks you are fairly new to programming in general. Your loop and the place you declare variables is kind of wrong already... – Kukeltje Jan 06 '17 at 09:37
  • All the more reason to get some good basic tutorials. Doing such low level jdbc is not very common anymore in java (or c#, but maybe in php or whatever it still is). Using JPA(2) or at least some persistence framework is. And the values of the variables are overridden in each iteration, loosing the previous ones and they are not known anymore outside the try/catch. – Kukeltje Jan 06 '17 at 09:54
  • @Kukeltje but is there no way to solve the above problem? –  Jan 06 '17 at 10:01
  • In the abovelinked duplicate, just substitute `ProductService` code with your JDBC boilerplate and then you'll be all set. – BalusC Jan 06 '17 at 10:11

0 Answers0