aspose file tools*
The moose likes JDBC and the fly likes Calling a row Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Calling a row" Watch "Calling a row" New topic
Author

Calling a row

James Eman
Ranch Hand

Joined: Mar 10, 2013
Posts: 45
i have been looking on the web for a few hours and haven't found a clear answer to my problem. is there a mysql command i can use to get the data from a row and a column like Select row 6 column Usernames. is there a simple command i just have been other looking.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 29241
    
139

James,
mysql has a limit clause you can use to get a certain row # within your query.


Do note that the order rows are stored in a table isn't guaranteed to be forever. It's more useful when doing paging because you have an order by clause in the query.


From: http://dev.mysql.com/doc/refman/5.5/en/select.html
With two arguments, the first argument specifies the offset of the first row to return, and the second specifies the maximum number of rows to return. The offset of the initial row is 0 (not 1):

SELECT * FROM tbl LIMIT 5,10; # Retrieve rows 6-15


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
chris webster
Bartender

Joined: Mar 01, 2009
Posts: 1478
    
  11

As Jeanne says, relational databases do not make any guarantees about the order in which rows are stored in a table or returned by a query. If you want to fetch rows in a particular order, you specify that order using an "ORDER BY..." clause in your query. If you want to fetch a particular row from a table, you tell the database how to identify that row via the WHERE clause. And you tell the database which columns to return for each row by specifying them in the SELECT clause of your query.

And use the LIMIT clause, as Jeanne says, to fetch a certain number of ordered rows at a time.


No more Blub for me, thank you, Vicar.
James Eman
Ranch Hand

Joined: Mar 10, 2013
Posts: 45
I was looking for a way to check the username and password match is there a better way then to call each row one by one?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60053
    
  65

Why do you need to check each row? Let the database do the work for you.

select count(*) from users where username=? and password=?

If the count is 0, the record doesn't exist.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
James Eman
Ranch Hand

Joined: Mar 10, 2013
Posts: 45
So it should look something like this?

Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 29241
    
139

Almost.

This won't compile as rs.next() returns a boolean to say whether there are any rows returned.


Since there will always be one row (and one column) returned for a count, you use
chris webster
Bartender

Joined: Mar 01, 2009
Posts: 1478
    
  11

Jeanne Boyarsky wrote:Almost.

This won't compile as rs.next() returns a boolean to say whether there are any rows returned.


Since there will always be one row (and one column) returned for a count, you use


If you are simply checking whether a row exists, and you don't actually want any data from the row, then you could just do "SELECT 1 FROM...". This will return a 1 as soon as a row is found, so it may be quicker than "SELECT COUNT(*)..." which always has to search the whole table (or index) to get the total count, even if there's only one matching row. If you get anything in your result set, you know a matching row was found. If the result set is empty, then you know there is no matching record.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Calling a row
 
Similar Threads
Keep getting this error and not sure why
Array Data Print Out
Long list of if statements: is there a better way to do this?
What is best way to display a results set from a database?
how to render a Combobox (or other things) in just one Cell