Get the App
SLTechnology News&Howtos  ›  Development  › 

Sample code from list to struts and spring

Shulou Source: shulou.com Published: 2022-06-01 02:34:23 10月03日 Update

This article mainly introduces the sample code from list to struts and spring, which is very detailed and has certain reference value. Friends who are interested must finish it!

Package com.sterning.commons

Import java.sql.Connection

Import java.sql.DriverManager

Import java.sql.PreparedStatement

Import java.sql.ResultSet

Import java.sql.SQLException

Import java.util.ArrayList

Import java.util.List

Import com.sterning.books.model.Student

Public class PageDAO {

Private Connection conn

Private PreparedStatement pstmt

Private ResultSet rs

Private static final String DRIVER = "com.mysql.jdbc.Driver"

Private static final String URL = "jdbc:mysql://localhost:3306/ssh3"

Private static final String USERNAME = "root"

Private static final String PASSWORD = "mysqling"

Private Student student

/ / Database connection

Public synchronized Connection getConnection () {

Try {

Class.forName (DRIVER)

Conn = DriverManager.getConnection (URL,USERNAME,PASSWORD)

} catch (ClassNotFoundException e) {

E.printStackTrace ()

Return null

} catch (SQLException e) {

E.printStackTrace ()

Return null

}

Return conn

}

/ / pagination query

Public ListqueryByPage (int pageSize, int pageNow) {

Listlist = new ArrayList ()

Try {

If (this.getConnection ()! = null & & pageSize > 0 & & pageNow > 0) {

Pstmt = this.getConnection () .prepareStatement (

"select * from student order by stu_id limit" + (pageNow*pageSize-pageSize) + "," + pageSize

);

Rs = pstmt.executeQuery ()

System.out.println ("it is ok now,hehe")

/ / float ff = pageNow*pageSize-pageSize

Int ii = 0

While (rs.next ()) {

Ii = ii + 1

/ / System.out.println ("it is empty" + ff)

Student = new Student ()

Student.setStu_id (rs.getInt (1))

System.out.println (student.getStu_id ())

Student.setStuName (rs.getString (2))

Student.setAddress (rs.getString (3))

Student.setStuPhone (rs.getString (4))

List.add (student)

}

System.out.println ("ii:" + ii)

}

} catch (SQLException e) {

E.printStackTrace ()

}

Return list

}

}

*

Package com.sterning.books.model

Public class Student {

Private int stu_id

Private String stuName

Private String address

Private String stuPhone

Public Student () {

}

Public int getStu_id () {

Return stu_id

}

Public void setStu_id (int stu_id) {

This.stu_id = stu_id

}

Public String getStuName () {

Return stuName

}

Public void setStuName (String stuName) {

This.stuName = stuName

}

Public String getAddress () {

Return address

}

Public void setAddress (String address) {

This.address = address

}

Public String getStuPhone () {

Return stuPhone

}

Public void setStuPhone (String stuPhone) {

This.stuPhone = stuPhone

}

}

*

Tags: Code examples content articles value interests students guys partners data databases more knowledge systems industry information information channels channels references help Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Huawei MariaDB Shulou Tech Info NVidia