Jsp/javabean listing data by page

Source: Internet
Author: User
Tags stmt
My first jsp paging code
Jsp file: pagedata. jsp // Display Data
Javabean: DataConn. java // connect to the database
Javabean: GetCount. java // number of data records obtained
DataConn. java file content:
Package aliang_org;
Import java. SQL .*;
Public class DataConn {
Public static Connection getDataConn (){
Connection conn = null;
Try {
Class. forName ("com. microsoft. jdbc. sqlserver. SQLServerDriver"). newInstance ();
Conn = DriverManager. getConnection ("jdbc: microsoft: sqlserver: // 127.0.0.1: 1433; DatabaseName = your", "your", "your ");
}
Catch (Exception ex ){
Ex. printStackTrace ();
}
Return conn;
}
}
GetCount. java file content:
Package aliang_org;
Import java. SQL .*;
Import java. util .*;
Import java. io .*;
Public class GetCount {
Private Connection conn;
Public GetCount () throws Exception {
Conn = DataConn. getDataConn ();
}
Public int getCounter () throws Exception {
Int ret = 0;
Statement stmt = conn. createStatement ();
ResultSet rset = stmt.exe cuteQuery ("select count (*) from UserInfos ");
While (rset. next ()){
Ret = rset. getInt (1 );
}
Return ret;
}
}
Pagedata. jsp file content:
<% @ Page contentType = "text/html; charset = gb2312" language = "java" %>
<% @ Page import = "aliang_org. *" %>
<% @ Page import = "java. util. *" %>
<% @ Page import = "java. io. *" %>
<% @ Page import = "java. SQL. *" %>
<Html>
<Head>
<Title>
Jsp/JavaBean listing data by page
</Title>
</Head>
<Body bgcolor = "# ffffff">
<H1> jsp/JavaBean listing data by page <Hr/>
<Jsp: useBean id = "dataConnection" class = "aliang_org.DataConn" scope = "page"/>
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.