|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
1200+ fellow developers rate and compare features of the top IDEs, like Visual Studio, Eclipse, RAD, Delphi and others, across 13 categories. Enjoy this FREE Download of the IDE User Satisfaction Study by Evans Data Corporation. Download Now!
|
|
#1
|
|||
|
|||
|
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
|
||||
|
||||
|
maybe use a newline char (\n)?
|
|
#3
|
|||
|
|||
|
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(); |
|
#4
|
|||
|
|||
|
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/So...ExecuteSQL.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; } } |
|
#5
|
||||
|
||||
|
Quote:
funny...i never saw any hint of html in the post...yet your point about "<br>" is correct. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Java Help > extracting and displaying text from a database |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|