Results 1 to 4 of 4
Like Tree1Likes
  • 1 Post By itswebin@gmail.com

Thread: Retrive data from database as text not as table

  1. #1
    vector_ever is offline Senior Member
    Join Date
    Jul 2013
    Posts
    187
    Rep Power
    2

    Default Retrive data from database as text not as table

    Hello,

    i need help, i have database from just 1 row and 1 column, in this database there are normal text like: " Hello every body to java wold with JSF"

    Any way i wish to display this data but also as a text no table
    as mentioned in the following link http://www.devmanual...e/viewdata.html it retrive a data and put them in table

    so how can i display it as pure text not as table

  2. #2
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,354
    Rep Power
    6

    Default Re: Retrive data from database as text not as table

    ... so just h:outputText the value? You only get a table if you use a component that produces a table.

    Your question is very similar to "How can I sit at a table without banging my head on it". Yeah, just stop banging your head.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    vector_ever is offline Senior Member
    Join Date
    Jul 2013
    Posts
    187
    Rep Power
    2

    Default Re: Retrive data from database as text not as table

    as you can see from the following code
    Java Code:
    //Display The Data
        public List<Wirote> getWordsList() {
            List wortList = new ArrayList<Wirote>();
            String url = "jdbc:mysql://localhost:3306/dbase";
            con = null;
            ps = null;
            result = null;
    
            try {
                Class.forName("com.mysql.jdbc.Driver");
    
                //get database connection
                con = DriverManager.getConnection(url, "root", "root");
    
    	//if(con==null){throw new SQLException("Can't get database connection");}
                ps = con.prepareStatement("select Words from dbase.dictionary");
    
                //get customer data from database
                result = ps.executeQuery();
    
                while (result.next()) {
                    Wirote wrt = new Wirote();
    
                    wrt.setWord(result.getString("Words"));
    
                    //store all data into a List
                    wortList.add(wrt);
                }
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                try {
    
                    con.close();
                    ps.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        
            return wortList;
        }
    where the Wirote is the name of the class, as you can see the data retrive from database and added to arraylist

    so it is not possible to display it as
    XML Code:
    h:outputText value="#{dictionary.wordsList}

  4. #4
    Join Date
    Apr 2014
    Location
    http://www.roytuts.com
    Posts
    51
    Rep Power
    0

    Default Re: Retrive data from database as text not as table

    <ui:repeat value="#{dictionary.wordsList}" var="wrd">
    <h:outputText value="#{wrd.word}" />&nbsp;
    </ui:repeat>
    gimbal2 likes this.

Similar Threads

  1. How to retrive multiple images from database in jsp?
    By ajay.aju1 in forum New To Java
    Replies: 1
    Last Post: 01-18-2013, 06:36 PM
  2. error in reading data from table in pidgree database
    By chethan_kc in forum Java Servlet
    Replies: 17
    Last Post: 02-18-2011, 03:11 PM
  3. Replies: 2
    Last Post: 02-03-2011, 09:23 AM
  4. Replies: 0
    Last Post: 02-09-2008, 09:22 PM
  5. Replies: 1
    Last Post: 02-01-2008, 02:21 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •