0

I have database table name form. And this database has three columnns: key_id, Key_name, and key_value. All the rows in the tables have different id, name, and value.

Lets say it has 100 rows, How would I go about getting values from certain rows, and not from other rows. For example, I want to get values from row 1-20, row 30, row 50-55 and row 80, etc.

How would I go about getting values in certain rows in java?

edit: each row are from a form. like row 1, key_name = name, key_value = john, row2 key_name = address, key_value = 123 main street, row 3 key_name = phoneNumber, key_value = 333-3333, and so on. Basically if you could imagine a job application, and each entry for firstName, lastName, address, etc, are entered into their own row, with their own value. I then need take the data from which ever role and replace certain text in a rtf document with the data (key_name) and show the key_value value, using java. I probably did not explain it right, but yeah???!? I need to know how to extract certain rows from a database using java.

  • 1
    It really depends from a lot of things what are you using: DB, java-frameworks, sort order to get row 1 and so on. Please provide a code: what have you already tried to do? Where are you stuck? – Vlad Bochenin Jan 04 '17 at 14:17
  • 1
    This is a general database question and you get that by writing a valid (SQL) Query that returns the row/rows you want. How you would send that query from java is another question, but it seems like you should first check out how databases and queries on them work before you worry about the java implementation. – OH GOD SPIDERS Jan 04 '17 at 14:17
  • You should be careful while implementing any logic that relies on the order in which the rows are returned by a query unless you are actually using something like an `ORDER BY` clause in your SQL query. – CKing Jan 04 '17 at 14:24
  • 2
    What do you mean by "row 1-20"? Do you mean where `key_id` has the values from 1 to 20 (assuming `key_id` ranges from 1 to 100 in the whole table)? That is easy, you use a `WHERE` clause: `WHERE id between 1 and 20`. If you mean anything else, you need to read again the basics of relational databases. There is no "row number 30" in a table. A table is a SET (as in set theory in math) - **not** an *ordered* set. There is no "first row", "second row" etc. – mathguy Jan 04 '17 at 15:19
  • Do you mean to ask how you would do it in java code without resorting to SQL? – IntelliData Jan 04 '17 at 17:07
  • Sorry for late response, I am trying to figure it out. Yes, I bunch of data in a table base and need to extract it using java. For example if you could imagine a job application form. each of the data, such as first name, last name, address, etc would each be a role. I have to extract only the needed rows from the database and put it into a document, using java – user2852918 Jan 04 '17 at 17:58
  • This still doesn't make sense to me. Why do you think you need to select the records by row numbers? Either you add an extra column for your row number or you should select the records by `key_name`. – vanje Jan 04 '17 at 21:19

0 Answers0