从list到struts和spring的示例代码
这篇文章主要介绍从list到struts和spring的示例代码,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!
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 ;
//数据库连接
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 ;
}
//分页查询
public List
List
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 ;
}
}
*********************************************
<!-- Add packages here -->
************************************
show*****
<%@ page="" contenttype="text/html; charset=UTF-8">
<%@taglib prefix="s" uri="/struts-tags">
Product Name | Price | Dianhua | Date of production |
undefinedundefined
********************************************
">进入学员系统
以上是“从list到struts和spring的示例代码”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注编程网行业资讯频道!
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341