Java to query the total number of records in a data table

Source: Internet
Author: User

Today, I read a book and write a small project example. I encountered a small problem to query the total number of records in a table. Baidu hasn't found a solution for a long time! Then I asked the predecessors in the group one by one to solve the problem.

 

PasteCodeYou will understand

Connection conn = dbconnection. getconnection (); string countsql = "select count (*) as result from message"; preparedstatement pstmt = NULL; resultset rs = NULL; int COUNT = 0; try {pstmt = Conn. preparestatement (countsql); RS = pstmt.exe cutequery (); While (RS. next () {COUNT = Rs. getint (1); // COUNT = Rs. getint ("result ");}}

Check the above Code! Record your problems ..

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.