If the world is so big and I am so small, what kind of face do I have? What do I take pride in! Only by constantly seeking knowledge can we get a little comfort.
I have always insisted on a theorem that the usage of language is always the most reliable in official documents.
Resultset:
1. Definition
Public interfaceResultset
The data table of the database result set. It is usually generated by executing a database query statement.
2. Obtain
Statement stmt = con. createstatement (
Resultset. type_scroll_insensitive,
Resultset. concur_updatable );
Resultset rs = stmt.exe cutequery ("select a, B from Table2 ");
3. Iteration
ResultsetThe object has a pointer to its current data row. Initially, the pointer is placed before the first line.NextThe method moves the pointer to the next row.ResultsetIf the object does not contain the next rowFalse, So you canWhileUse it in a loop to iterate the result set.
While (Rs. Next ())
{
}
4, Value
ResultsetInterface to retrieve column values from the current rowObtainMethod (Getboolean,Getlong). You can use the index number or name of a column to retrieve the value. Generally, column indexes are more efficient. The column number starts from 1. To achieve maximum portability, you should read the result set columns in each row from left to right, and each column can only be read once.
Rs. getstring ();
The above part is taken from the Chinese version of jdk1.5. If some problems are caused by version problems, please forgive me. We have not provided a detailed list of all resultset information here. You can refer to the document on your own. But inProgramBasically, we only use the parts listed above. I guess in most cases, we seldom use resultset for data updates in Web applications? Therefore, I have not listed the related content about data update. If you are interested, you can view it on your own.
The following is a question: I want to query all the data in a table from the database. It is estimated that there are 100 rows, but I certainly don't know how many rows. We use resultset for storage. What should I do if I want to retrieve a field value in the first column of the last row? Is there any better way besides iteration? I may even use this method multiple times: I want to retrieve any column of any row at will. What should we do? Have you considered database connection issues?
At my current knowledge level, I can't do anything about the above problems on the existing resultset. I don't know what to do? I rummaged through my documents in the Chinese version of jdk1.5 and couldn't find a good answer. I suddenly felt that the document was outdated. Java has a higher usage rate than. net. Can't I find a dataset similar to a datatable? I guess there is, but the document I used seems to be for the Java SE version and may not involve more in-depth enterprise-level applications.
Before explaining the result, let's talk about how we store datasets. There is no doubt that in the SSH framework, all users use the Entity List, which facilitates iteration and positioning. In addition, Struts labels are used for presentation. However, I basically refuse to use it. First, currently, the query language hql used by SSH in combination with list is not easy to use or fast (I personally think ). Second, for redundant Fields, I only want to query two fields in a table. There is no need to query dozens of fields in the entire table! Third, is there any perfect solution to the table connection problem? Is there anything better than join? Even if some people do not use the ORM framework, they first query the resultset and then iterate and encapsulate it into the Object List. Is this really worthwhile?
Result:
1. Definition
The data table of the database result set. Full name: javax. servlet. jsp. jstl. SQL. Result
2. Obtain
To get the result, we must first get the result and then use resultsupport. toresult (RS) to convert it.
Statement stmt = con. createstatement (
Resultset. type_scroll_insensitive,
Resultset. concur_updatable );
Resultset rs = stmt.exe cutequery ("select a, B from Table2 ");
Result rst = resultsupport. toresult (RS );
3. Iteration
Unfortunately, you cannot access the Internet or download or read from your place of residence.Source code, The information is also relatively scarce, du Niang, Gu Ge and search sister in this problem is also not powerful, and finally can only try a little bit. I found the following usage:
For(SortedmapItem: RST. getrows ()){
}
This iteration method is not more complex than the resultset method. If you want to, you can make a slight modification so that the iteration can start from any row or any end.
4, Value
Because each row in the result isSortedmap,So follow the rules:
Object value = item. Get (key );(SortedmapOf course, some other methods)
After introducing the two datasets, I believe everyone knows about them. In fact, they share the same role and usage. In most cases, there is almost no problem with the two.
Now I try to use the result to solve the problem that the red mark cannot solve.
1. Obtain the first column of the last row.
Object o = RST. getrowsbyindex () [RST. getrowcount ()] [0];
Isn't that simple enough?
2. Obtain any column in any row
Object o = RST. getrowsbyindex () [row Index] [column Index];
Note: Be sure to prevent exceptions that exceed the index. Other usage will be developed later. In addition, it should be noted that once we obtain the result from resultset, the database connection will be released without occupying the connection.
Some people say that I will use the Object List to let resultset and result go to hell.
I don't care! Fast, direct, simple, and discard redundant fields. Am I right?
As for how you choose, let's proceed with your mind. Code farmers are also emotional.
Next episode notice: the home page displays the role menu and web page architecture.