#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Posts
    0
    Rep Power
    0

    extracting and displaying text from a database


    Hello, I was curious if there is a certain method for extracting information of type Text from a database? The problem that I am having is that when I retrieve the data none of the newlines are being printed... For example, if I insert the following text into the database:

    The First Line
    The Second Line


    What gets outputed is:
    The First Line The Second Line


    Anyone know how to fix this?
  2. #2
  3. SwollenMember
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Location
    the master control
    Posts
    264
    Rep Power
    15
    maybe use a newline char (\n)?
  4. #3
  5. No Profile Picture
    Moderator =(8^(|)
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2002
    Location
    Sacramento, CA
    Posts
    1,710
    Rep Power
    14
    This sounds like an html issue. Newlines don't display in your browser, you have to replace them with <br>. Try something like:

    dboutput = Pattern.compile( "/\n/" ).matcher( dboutput ).replaceAll( "<br>\n" ).toString();
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2002
    Location
    Vicksburg, MS
    Posts
    7
    Rep Power
    0
    In java, the result from a jdbc sql query is a result set which is read and processed something in a program like the one at:
    http://www.quantumhyperspace.com/Sou...xecuteSQL.java

    (The source code was too long to post here)

    The following example illustrates adding a new line character to each line read from a Buffered Reader which might work in your problem :

    /* Example.java
    */
    import java.io.*;

    public class Example{

    public static void main(String[] args){
    Example example = new Example();
    example.test();
    }

    public void test(){
    String someString = "la la la la la la la\rla la la la la la la\rla la la la la la la\r";
    String string = processLongString(someString);
    System.out.println(string);
    }

    public String processLongString(String s){
    String processedText = "";
    try{
    StringReader sr = new StringReader(s);
    BufferedReader br = new BufferedReader(sr);
    String nextLine = "";
    while ((nextLine = br.readLine()) != null){
    processedText = processedText + nextLine + "\n";
    }
    }catch(IOException ioe){
    System.err.println("IOException: " + ioe.getMessage());
    }
    return processedText;
    }
    }
  8. #5
  9. SwollenMember
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Location
    the master control
    Posts
    264
    Rep Power
    15
    This sounds like an html issue. Newlines don't display in your browser, you have to replace them with <br>.
    funny...i never saw any hint of html in the post...yet your point about "<br>" is correct.

IMN logo majestic logo threadwatch logo seochat tools logo