Example of Jsp+mysql+java class optimization paging

Source: Internet
Author: User
Tags mysql database

In the JSP often use the data in the query database, the common practice is to use the SQL statement "SELECT * FROM tablename-id desc", this practice has a disadvantage, when the database is very large, the speed of the query will be slow, In ASP, there is a method "select Top" &recpage& "* FROM TableName where ID is not in (select Top" & (recpage* (currentpage-1)) &am p; "ID from the products ORDER by id DESC" desc "recpage for each page, CurrentPage is the current number of pages. But there is no" select top * "in the MySQL database. statement, and the alternative statement is "SELECT * FROM tablename limit position, counter" position indicates where to start the query, if 0 is from the beginning, and counter represents the number of queries, through jsp+ Java query database, the data obtained by the query is temporarily stored in the JSP by the Java class, directly from the memory to extract data, the speed has been greatly improved.

The following example is a part of the program about user comments, if you have a Web site dedicated to users, and now want to interact with friends, add a comment is a good idea, then you can add the following program, and build a table which adds a photo_id field and your table associated with the Can let the netizen to your picture reviews.

Comment.java is a review of the class

<--------Comment.java------->
Package dbconnection;
public class Comment
{
Private String ID;
Private String album_id;
Private String title;
Private String content;
Private String Modi_time;
Private String user;
public void SetId (String IDs)
{
This.id=ids;
}
public void setalbum_id (String album_ids)
{
This.album_id=album_ids;
}
public void Settitle (String titles)
{
This.title=titles;
}
public void SetContent (String contents)
{
this.content=contents;
}
public void Setmodi_time (String modi_times)
{
This.modi_time=modi_times;
}
public void SetUser (String users)
{
This.user=users;
}
Public String getId ()
{
return ID;
}
Public String getalbum_id ()
{
return album_id;
}
Public String GetTitle ()
{
return title;
}
Public String getcontent ()
{
return content;
}
Public String Getmodi_time ()
{
return modi_time;
}
Public String GetUser ()
{
return user;
}
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.