resultset problem
I want to display data from db using servlet as it is.
I used the <pre> html tag but the wdith bcame out. I tried to use css but was unable to adjust the width of the <pre> tag.
Is there any solution to retrieve data as it is from db in java servlet?
any help please
thanks in advance
[328 byte] By [
farakha] at [2007-11-26 22:47:57]

Plz help me as my work is pending for the last some days and I am unable to find the solutionthanks again
hi,use table or div as the following:<table> <tr><td>Col1 Name</td> <td>Col2Name</td> </tr></table>see http://www.w3schools.com for more html or css
response.setContentType("text/html");
PrintWriter out = new PrintWriter (response.getOutputStream());
out.println("<html>");
out.println("<head><title>Error</title></head>");
out.println("<body>");
out.println("<table>");
for(int i=0; i<10; i++){
out.println("<tr>");//new table row
out.print("<td>");
out.println("COL1 DATA HERE");
out.print("</td>");
out.print("<td>");
out.println("COL2 DATA HERE");
out.print("</td>");
out.print("<td>");
out.println("COL3 DATA HERE");
out.print("</td>");
....
out.println("</tr>");
}
out.println("</table>");
out.println("</body></html>");
you can also add empty row after every row you add.
hth
> hi,
>
> use table or div as the following:
>
> <table>
><tr>
><td>Col1 Name</td> <td>Col2Name</td>
> tr>
> </table>
>
> see http://www.w3schools.com for more html or css
thanks for your advise but <div> <table> and <td> cannot control the width of <pre> tag
Java will certainly have solution to control the result set and to display inserted data as it is
e.g. when we receive the email or sending the email the display data remains with same format i.e. lines, paragraphs, bullets, spaces etc.
thanks
generally html elements have width attribute to control the element span. http://www.w3schools.com/tags/tag_pre.asp
> generally html elements have width attribute
> to control the element span.
> http://www.w3schools.com/tags/tag_pre.asp
try <pre> on your own link test demo:
http://www.w3schools.com/tags/tryit.asp?filename=tryhtml_pre
and you'll find its not working that's why I am here
thanks again for cooperation
So what your really asking is a pure HTML question, right? Then why don't you ask on an HTML forum, rather than a Java forum?
And, AFAIK, you can't affect the "width" of a "pre" element. The "pre" tag means, preformatted.Changing the "width" of a "pre" tag, essentially means that it is no longer a "pre" tag, IMO.
Edit: And that posted link by Java_2006 only supports this, as it says itself, that the width attribute of the "pre" tag is deprecated.
> So what your really asking is a pure HTML question,
> right? Then why don't you ask on an HTML forum,
> rather than a Java forum?
>
> And, AFAIK, you can't affect the "width" of a "pre"
> element. The "pre" tag means, preformatted.
> Changing the "width" of a "pre" tag, essentially
> means that it is no longer a "pre" tag, IMO.
>
> Edit: And that posted link by Java_2006 only
> supports this, as it says itself, that the width
> attribute of the "pre" tag is deprecated.
Thanks masijade for your reply
why I have posted here because its related to JDBC. Using <pre> tag is my mind but I am sure I am not right.
In this forum I am trying to solve the data retrieval problem as I am not able to display data in its origional shape.
Please help and guide me as to how can I display data in origional shape using servlet
thanks again
So define what you mean by "as it is".
Do you have a large text field in your row whicj contains multiline data that you want to display?
If so, run it through a regex replacing "newline" with
, a "space" at the beginning of a line with ?and every "tab" with a specific amount of tags (say four tags four every tab).
This is about as close as you can get without using pre, and if you use pre, don't expect to be able to restrict its width. Why is it so wrong to leave the width of the "pre" area alone? Is it such a bad thing if the user needs to scroll?
[nobr]Thanks for guidence.
I have seen the regex articles and they are really helpful. I am facing to run the following code as this is giving error that Unable to resovle replaceAll(); methodString aa = text.replaceAll("\\n", "<br>");
I have jdk1.4 and I checked it using java -version from command prompt but don't know whats the problem
thanks again for help[/nobr]
Is "text" a String? If not it should be.
Then you are going to need to post some more code around the problem area and the full error text. If text is a String, and you are using 1.4.2 then replaceAll(String, String) should definately be found.
[nobr]very simple code thats not working plz see it:
public class Test{
public static void main(String arg[]){
String text="Hello\nWorld";
String text1=text.replaceAll("\\n","<br>");
System.out.println("text1");
}
}
Error:Test.java:4: cannot resolve symbol
symbol: method replace.All (java.lang.String, java.lang.String)
location: class java.lang.String
java -version
java version "1.4.2_10"
java TM 2 Runtime Environment, Standard Edition (build 1.4.2_10-b03)
Java HotSpot TM Client VM (build 1.4.2_10-b03, mixed mode)
[/nobr]
[nobr]> very simple code thats not working plz see it:
> public class Test{
> public static void main(String arg[]){
> String text="Hello\nWorld";
> String text1=text.replaceAll("\\n","<br>");
> System.out.println("text1");
> }
> }
>
> Error:Test.java:4: cannot resolve symbol
> symbol: method [b]replace.All[/b] (java.lang.String, java.lang.String)
> location: class java.lang.String
>
> java -version
> java version "1.4.2_10"
> java TM 2 Runtime Environment, Standard Edition
> (build 1.4.2_10-b03)
> Java HotSpot TM Client VM (build 1.4.2_10-b03, mixed
> mode)
>
First of all, what does
javac -version
Also, where is the mistake here, because the posted code and the posted error message do not match.
// posted code
String text1=text.replaceAll("\\n","<br>");
// posted error message
symbol: method replace.All (java.lang.String, java.lang.String)
notice the "." in the error message replace "." All
If that is the real error message, then that is your error. Remove the "."[/nobr]
[nobr]public static void main(String arg[]) {
String text = "Hello\nWorld";
String text1 = text.replaceAll("\\n", "<br>");
System.out.println(text1); //print text1 !!
}
[/nobr]
[nobr]> public static void main(String arg[]) {
> String text = "Hello\nWorld";
> String text1 = text.replaceAll("\\n", "<br>");
> System.out.println(text1); //print text1 !!
> }
>
I just copy, pasted the above code. Even then its not recognizing replaceAll method. May I install jdk again?[/nobr]
[nobr]> > public static void main(String arg[]) {
> > String text = "Hello\nWorld";
> > String text1 = text.replaceAll("\\n", "<br>");
> > System.out.println(text1); //print text1 !!
> > }
> >
>
> I just copy, pasted the above code. Even then its not
> recognizing replaceAll method. May I install jdk
> again?
That, also, had nothing to do with the problem (it did fix a future problem, but it has nothing to do with your current problem). Can you reread what I posted last time, and answer my questions there.
Edit: Forget about javac -version, it doesn't exist. I made a mistake as javac does not have that option.
However, look at the posted error message again, the one you posted says replace.All which is very different from replaceAll
That "." makes, of course, a world of difference. If that is the real message, then find the real line that it references (which is not in the code you posted) and change replace.All to replaceAll
If you (somehow or other) messed up on copying and pasting the error message, and it really says replaceAll, rather than replace.All, which posted, then your problem is that you are using a jdk prior to 1.4.whatever
And, no, that java -version returning 1.4.whatever, does not confirm that using a 1.4.whatever jdk. It confirms that you are suing a 1.4.whatever jre, which is something completely different. Which one you are getting depends on your PATH, and how many different java versions you have installed.[/nobr]
are you using a java IDE ?
> are you using a java IDE ?No Sir, I am working in notepad with command prompt compilation
astonishing !!
could you execute this program and post what it displays plz ?
import java.util.Enumeration;
import java.util.Properties;
public class SysProps {
public static void main(String[] args) {
//System.getProperties().list(System.out);
Properties props = System.getProperties();
Enumeration keys = props.keys();
String key;
while (keys.hasMoreElements()) {
key = (String) keys.nextElement();
System.out.println(key+":"+props.getProperty(key));
}
}
}
java_2006 thanks for your replyI runned this program and plz view the result: http://pearlofpeace.net/j/index.htmlthanks
I think that your program uses the oracle jdk 1.1.8 !! So you have to set your path properly.
(Remove Oralce/jre/1.1.8/bin from your env. variable path)
Try to execute your program like the following :
compilation:
g:/jdk1.4/bin/javac YOUR_PROGRAM_NAME
Running:
g:/jdk1.4/bin/java YOUR_PROGRAM_NAME
hth
> I think that your program uses the oracle jdk 1.1.8
> !! So you have to set your path properly.
> (Remove Oralce/jre/1.1.8/bin from your env.
> variable path)
>
> Try to execute your program like the following :
>
> compilation:
> g:/jdk1.4/bin/javac YOUR_PROGRAM_NAME
>
> Running:
> g:/jdk1.4/bin/java YOUR_PROGRAM_NAME
>
>
> hth
I don't know whats the hell is going. I tested the program using the
g:/jdk1.4/bin/javac myProg
but the same result
I think I should download the newer version of jdk and then test it
I am really thankful to you from the core of my heart to get me your precious time.
After downloading and installing the new version I'll come back to you
thanks again