473,385 Members | 1,546 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,385 software developers and data experts.

How to insert a tag element in longtext field used as XML

hey,

i have created a table called book_table
Expand|Select|Wrap|Line Numbers
  1. mysql> describe book_table;
  2. +-----------------+--------------+------+-----+---------+----------------+
  3. | Field           | Type         | Null | Key | Default | Extra          |
  4. +-----------------+--------------+------+-----+---------+----------------+
  5. | bookid          | int(15)      | NO   | PRI | NULL    | auto_increment |
  6. | book_type       | varchar(15)  | NO   |     | NULL    |                |
  7. | title           | varchar(100) | NO   |     | NULL    |                |
  8. | author          | varchar(70)  | NO   |     | NULL    |                |
  9. | type            | varchar(15)  | NO   |     | NULL    |                |
  10. | competency      | varchar(40)  | NO   |     | NULL    |                |
  11. | upload_link     | varchar(200) | YES  |     | NULL    |                |
  12. | owner           | varchar(40)  | NO   |     | NULL    |                |
  13. | status          | varchar(20)  | NO   |     | NULL    |                |
  14. | sl              | varchar(40)  | YES  |     | NULL    |                |
  15. | is_reissued     | varchar(3)   | YES  |     | NULL    |                |
  16. | issued_to_users | longtext     | NO   |     | NULL    |                |
  17. | review          | longtext     | NO   |     | NULL    |                |
  18. | details         | longtext     | NO   |     | NULL    |                |
  19. +-----------------+--------------+------+-----+---------+----------------+
  20.  
suppose for a perticular tuple the value in review field is as follows:


<reviews><user><user_name>321654</user_name><review>This is a nice book.</review></user></reviews>


but for one book there can be many reviews from different user.

so i want to insert one more tag at the end of the exiting user tag. It should look something like this.

<reviews><user><user_name>321654</user_name><review>This is a nice book.</review></user><user><user_name>654321</user_name><review>I didnt like this book.</review></user></reviews>

please can anybody tell me how to do this from a jsp page.
i will be very grateful. thankyou.
Jun 26 '10 #1
1 1918
Atli
5,058 Expert 4TB
This is not how you should use a MySQL database. The first rule of relational database design: No field should contain more than a single value. (Or rather; no table should contain repeating groups of data... but that's just semantics.)

Basically, if you need one row in a table (e.g. one book) to have multiple, identical values (e.g. reviews) then you should put those values in a separate table, which would list all the values and the ID of the book it belongs to.

For example, your tables should be designed something like this:
Expand|Select|Wrap|Line Numbers
  1. +--------------+     +--------------+
  2. | book         |     | reviews      |
  3. +--------------+     +--------------+
  4. | book_id (PK) |1---*| book_id (PK) |
  5. | name         |     | user_id (PK) |
  6. +--------------+     | value        |
  7.                      +--------------+
There each row in the reviews table is linked to a row in the book table, and also lists a user ID (which would presumably be linked to a user table). Each user would then be able to post a review about each book.

Example values, where two users review two books, might look like:
Expand|Select|Wrap|Line Numbers
  1. -- book --
  2. +---------+-------------+
  3. | book_id | name        |
  4. +---------+-------------+
  5. |       1 | First Book  |
  6. |       2 | Second Book |
  7. +---------+-------------+
  8.  
  9. -- reviews --
  10. +---------+---------+-------------------------+
  11. | book_id | user_id | value                   |
  12. +---------+---------+-------------------------+
  13. |       1 |  321654 | This is a nice book.    |
  14. |       1 |  654321 | I didnt like this book. |
  15. |       2 |  321654 | I also like this one.   |
  16. |       2 |  654321 | This one isn't bad...   |
  17. +---------+---------+-------------------------+
Jul 1 '10 #2

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

Similar topics

5
by: Iain Porter | last post by:
Hi, I'm trying to store large strings to a database, so am using the text field type (LongText). I have used this before when storing the html of a webpage, and was able to store more than 255...
1
by: Leura | last post by:
I have a new XML document parsed in as DOM. Then I have an element to insert according to the order spesified in a schema. For example: I have a XML: <book>...
2
by: Brian | last post by:
I'm trying out a script called mktree.js < http://www.mattkruse.com/javascript/mktree/ > I want to add an expand all button to the script, using the DOM insertBefore method. I added a function to...
1
by: sudhaoncyberworld | last post by:
I have scenario like below, in table we have insert row & in row we have insert cell, but i need to insert an table element in td, Here in td i have tbl1 & tbl2 as child and now i want to insert...
5
by: Mike Dee | last post by:
Is it possible to dynamically create a new form object (form1), then create a new form field object and add it form1, and then add form1 to the current document? I need to do all this in script...
4
by: Kim | last post by:
Im trying to add an element (<Tag>value</Tag>) under a certain child, but something goes wrong. It gets inserted just before the root end tag instead of the location I tought it would. I load an...
3
by: indhu | last post by:
Hi all Is it possible to insert 5 table field into single form. all the table has same values except typeof work 11 columns 6 rows i ve to display. totally 72 fields suggesstion and help...
2
by: E.F | last post by:
Hi, i try to manage xml with vb.net and i have to insert this element between 2 elements: <QUATRE Attr_1="400" Attr_2="100" /> in my xml file witch is looking like that : <TEST> <Etape_1>...
2
bugboy
by: bugboy | last post by:
Hi, I have a very long array with sequential numeric keys. What is the best method for inserting an element in the middle thus bumping all following elements along one key.. Like the function...
0
by: ffenton | last post by:
I have a problem with text being inserted into a mysql database containing hidden characters. The text arrives there via multiple stages. Basically it is copied from Ms Word into an Ms Access rich...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.