473,396 Members | 1,866 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Problem in Displaying the Mysql data in Browser using Jsp

Hi ,
i have created table with only one field for the type of varchar(8000) . I am stroed bulk amount of data in that field.

The size i have specified is enough for the field to occupy my data.

I am storing "Text file" as Data to that filed.when i am viewing contents present in the table it shows what actual contents present in that text file like one by one line of data.

But when i am reterving the data in the browser using Jsp, it shows all contents present in the filed is displayed without any alignment. i want see output as i have seen/stored in the database.

could please suggest me the right way to proceed this is problem .. is this the problem in mysql or Jsp?
Nov 13 '08 #1
13 4322
r035198x
13,262 8TB
Get the text into a string then use the replaceAll method to replace all \n with <BR />.
Careful with your regex for matching \n. You need four \ to match one \.
Nov 13 '08 #2
thanks for reply..
actually the problem is ,

database -table -record is to be updated through linux, from where some text file has to be created and shell script is executed for storing the text file to database as record in single field.after storing the text file it has to be retrieved in browser using Jsp program.

so how i can replace the \n to <br \> tag when i dont have a \n in my text file. i really confused.

database table data shown

| total: used: free: shared: buffers: cached:
Mem: 515952640 510210048 5742592 0 2199552 118583296
Swap: 1077469184 572231680 505237504
MemTotal: 503860 kB
MemFree: 5608 kB
MemShared: 0 kB
Buffers: 2148 kB
Cached: 62224 kB
SwapCached: 53580 kB
Active: 382952 kB
ActiveAnon: 354608 kB
ActiveCache: 28344 kB
Inact_dirty: 72288 kB
Inact_laundry: 14928 kB
Inact_clean: 6720 kB
Inact_target: 95376 kB
HighTotal: 0 kB
HighFree: 0 kB
LowTotal: 503860 kB
LowFree: 5608 kB
SwapTotal: 1052216 kB
SwapFree: 493396 kB
HugePages_Total: 0
HugePages_Free: 0
Hugepagesize: 4096 kB |

1 row in set (0.44 sec)


code attached
Expand|Select|Wrap|Line Numbers
  1.  
  2. <%@ page import="java.sql.*" %>
  3. <%@ page import="javax.servlet.*" %>
  4. <%@ page import="javax.sql.*" %>
  5. <%@ page import="javax.servlet.http.*" %>
  6.  
  7. <%
  8. ResultSet rs=null;
  9. Connection con =null;
  10.  %>
  11.  
  12. <html>
  13. <head>
  14. <h3>Sample Database Reterival</h3></head>
  15. <table><tr><th>Memory Information</th></tr>
  16.  
  17. <body>
  18.  
  19. <%
  20. try
  21. {
  22. Class.forName("com.mysql.jdbc.Driver");
  23. con=DriverManager.getConnection("jdbc:mysql://192.168.1.8:3306/test","root","prastsys");
  24. Statement st=con.createStatement();
  25. rs=st.executeQuery("select * from charchk");
  26. while(rs.next())
  27. {
  28. String mem=rs.getString(1);
  29. %>
  30.  
  31. <tr>
  32. <td>
  33. <%
  34. out.println(mem);
  35. %>
  36. <br>
  37. </td>
  38. <br>
  39. </tr>
  40. <%
  41. }
  42. %>
  43. </table>
  44. <%
  45. }
  46. catch(Exception e)
  47. {
  48. out.println(e);
  49. }
  50. %>
  51.  
  52. </body>
  53. </html>
  54.  
output from browser:

Sample Database Reterival

Memory Information
total: used: free: shared: buffers: cached:
Mem: 515952640 510210048 5742592 0 2199552 118583296 Swap: 1077469184 572231680 505237504
MemTotal: 503860 kB MemFree: 5608 kB MemShared: 0 kB Buffers: 2148 kB Cached: 62224 kB SwapCached: 53580 kB
Active: 382952 kB ActiveAnon: 354608 kB ActiveCache:
28344 kB Inact_dirty: 72288 kB Inact_laundry: 14928
kB Inact_clean: 6720 kB Inact_target: 95376 kB HighTotal: 0 kB HighFree: 0 kB LowTotal: 503860 kB LowFree: 5608 kB SwapTotal:
1052216 kB SwapFree: 493396 kB HugePages_Total: 0 HugePages_Free: 0 Hugepagesize: 4096 kB

--

this is what the output displayed in browser. there is no order /alignment has done when displayed but mysql shows the contents by one by one line in order .. so please tel me some detailed solution for this..

Thank you
Nov 13 '08 #3
r035198x
13,262 8TB
1.) Better remove all that database connection code from the JSP. The JSP must only get the results and display them.
2.) Did you try passing that string to a replaceAll method like I suggested?
Nov 13 '08 #4
1.) Better remove all that database connection code from the JSP. The JSP must only get the results and display them.
2.) Did you try passing that string to a replaceAll method like I suggested?

i dont know how pass the string to replace all method that you would suggested?
i dont have '\n' in my text file or a string i have,then how can i use replace all method to convert \n to <br />tag?
help me.
Nov 13 '08 #5
r035198x
13,262 8TB
Expand|Select|Wrap|Line Numbers
  1. String mem=rs.getString(1);
  2. mem = mem.replaceAll("\\\\n","<BR />");
Nov 13 '08 #6
Expand|Select|Wrap|Line Numbers
  1. String mem=rs.getString(1);
  2. mem = mem.replaceAll("\\\\n","<BR />");
still i am not get the required output after applying the replaceAll method that you would suggested . is there any other solution for this problem?
Nov 14 '08 #7
r035198x
13,262 8TB
Can you post the code you used?
Nov 14 '08 #8
Can you post the code you used?
Here is the code i used.
Expand|Select|Wrap|Line Numbers
  1.  
  2. <%@ page import="java.sql.*" %>
  3. <%@ page import="javax.servlet.*" %>
  4. <%@ page import="javax.sql.*" %>
  5. <%@ page import="javax.servlet.http.*" %>
  6.  
  7. <%
  8. ResultSet rs=null;
  9. Connection con =null;
  10.  %>
  11.  
  12. <html>
  13. <head>
  14. <h3>Sample Database Reterival</h3></head>
  15. <!--<table><tr><th>Memory Information</th></tr>-->
  16.  
  17. <body>
  18.  
  19. <%
  20. try
  21. {
  22. Class.forName("com.mysql.jdbc.Driver");
  23. con=DriverManager.getConnection("jdbc:mysql://192.168.1.8:3306/test","root","prastsys");
  24. Statement st=con.createStatement();
  25. rs=st.executeQuery("select * from charchk");
  26. while(rs.next())
  27. {
  28.  String mem=rs.getString(1);
  29.  mem = mem.replaceAll("\\\\n","<BR />");
  30.  
  31. out.println(mem);
  32. %>
  33. <br>
  34.  
  35. <%
  36. }
  37.  
  38. }
  39. catch(Exception e)
  40. {
  41. out.println(e);
  42. }
  43. %>
  44. </body>
  45. </html>
  46.  
  47.  
Nov 14 '08 #9
r035198x
13,262 8TB
What if you wrap the string in <pre> </pre> tags?

P.S You really should not be connecting to databases in JSP code.
Nov 14 '08 #10
What if you wrap the string in <pre> </pre> tags?

P.S You really should not be connecting to databases in JSP code.


I really i dont know what to proceed next? i think you are saying that dont use Jsp code for DB connection isn't it? then tell me how i can overcome this problem..can u give me an idea for this problem or any other alternative or how to proceed further??
Nov 14 '08 #11
r035198x
13,262 8TB
Basically mixing Java code and HTML is a bad idea and should be kept to a bare minimum. Doing so creates lots of maintenance headaches and makes your application slower. All the Java code should be in Servlets and utility classes. The JSP must only be concerned with getting results from those classes and displaying that data.

P.S Did you try the pre tags on the text?

P.PS How did you decide that the data is well formatted in the database? Did you run a select from the command line or similar?
Nov 14 '08 #12
i didnt use/try the [pre] tag in text.

you asked that, how did i decided Mysql table is well formatted?
for that i checked Mysql table using select query.

results showw like this,

mysql> select * from charchk;

| memory |
------------------------------------------------------------------------
| total: used: free: shared: buffers: cached:
Mem: 515952640 510210048 5742592 0 2199552 118583296
Swap: 1077469184 572231680 505237504
MemTotal: 503860 kB
MemFree: 5608 kB
MemShared: 0 kB
Buffers: 2148 kB
Cached: 62224 kB
SwapCached: 53580 kB
Active: 382952 kB
ActiveAnon: 354608 kB
ActiveCache: 28344 kB
Inact_dirty: 72288 kB
Inact_laundry: 14928 kB
Inact_clean: 6720 kB
Inact_target: 95376 kB
HighTotal: 0 kB
HighFree: 0 kB
LowTotal: 503860 kB
LowFree: 5608 kB
SwapTotal: 1052216 kB
SwapFree: 493396 kB
HugePages_Total: 0
HugePages_Free: 0
Hugepagesize: 4096 kB |

---------------------------------------------
so that i decided it is well formatted .. or tell me my thought is wrong with reason. actually i am not storing the value to that filed directly. fFom linux i have inserted record .
Nov 14 '08 #13
r035198x
13,262 8TB
So you are trying to display many rows line by line rather than one formatted row?
Your break tag is not correct in your JSP. Make that <BR /> instead.
Nov 14 '08 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Dariusz | last post by:
Below is part of a code I have for a database. While the database table is created correctly (if it doesn't exist), and data is input correctly into the database when executed, I have a problem...
5
by: Blaktyger | last post by:
How can this be done? Images are stored in a LONGBLOB field. When I try to display them, it prints out the binary data as it is... Thank you
0
by: Donald Tyler | last post by:
Then the only way you can do it that I can think of is to write a PHP script to do basically what PHPMyAdmin is trying to do but without the LOCAL in there. However to do that you would need to...
8
by: BiNZGi | last post by:
Hi I have reduced the problem to this code: <form> <table border="0" cellpadding="0" cellspacing="0" width="100%"> <tr> <td><input type="text" style="width: 100%;" value="Lorem ipsum dolor...
5
by: Douglas Hay | last post by:
I have a C++ Builder APP that uses the Advantage database. I want to export data from the Advantage tables to a MySQL database on my website. What is the best way to get my data into the MySQL...
5
by: Tomaz Koritnik | last post by:
Hi I have many short HTML files stored in a binary stream storage to display descriptions for various items in application. HTML would be display inside application using some .NET control or...
13
by: David W. Fenton | last post by:
I've been struggling the last two days with something I thought was very easy, which is to open a web page with a form on it and populate the form with data passed in a query string (either POST or...
30
by: Einstein30000 | last post by:
Hi, in one of my php-scripts is the following query (with an already open db-connection): $q = "INSERT INTO main (name, img, descr, from, size, format, cat, host, link, date) VALUES ('$name',...
2
by: xtremebass | last post by:
Hi , i have created table with only one field for the type of varchar(8000) . I am stroed bulk amount of data in that field. The size i have specified is enough for the field to occupy my data....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.