從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/ssh2" ;
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*****
Product Name | Price | Dianhua | Date of production |
********************************************
[@more@]hehe來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/93029/viewspace-1018130/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Struts 和Spring ioc 整合Spring
- 從EXCEL導PRICE LIST到OM單價庫Excel
- [求助] STRUTS2和SPRING整合問題Spring
- struts與Spring整合Spring
- struts和spring結合的問題(線上等~~)Spring
- 觀察者模式——從JDK到Spring模式JDKSpring
- 從代理機制到Spring AOPSpring
- spring整合struts2Spring
- Struts+Spring整合3Spring
- [我]Struts+Spring整合Spring
- struts與spring 的整合Spring
- 框架(Spring、Struts2和Hibernate三者)整合框架Spring
- Struts2【與Spring整合】Spring
- spring整合struts2(續)Spring
- 如何組合Struts+Spring?Spring
- [我]Struts+Spring的整合Spring
- [文件中]Struts與Spring整合Spring
- 微服務 | Spring Cloud(一):從單體SSM 到 Spring Cloud微服務SpringCloudSSM
- Spring AOP 使用介紹,從前世到今生Spring
- 從Spring中學到的【2】--容器類Spring
- 註解:從一個namespace跳轉到另外一個namespace,Struts2namespace
- mybatis+spring+struts2框架整合MyBatisSpring框架
- 求助於struts+spring+hibernateSpring
- Spring+struts 的問題 急!~~Spring
- spring struts hibernate 優缺點?Spring
- [摘]Struts+Spring+Hibernate整合Spring
- JSF和strutsJS
- Spring原始碼分析之AOP從解析到呼叫Spring原始碼
- Struts2和Spring2結合時報的一個錯Spring
- 【Struts】:Struts1和Struts2的區別與聯絡
- Struts1、Struts2、Hibernate、Spring框架工作原理介紹Spring框架
- 使用 Spring 更好地處理 Struts 動作----三種整合 Struts 應用程式與 Spring 的方式Spring
- struts+spring+hibernate感悟(轉載)Spring
- Struts+Spring+Hibernate練習(完整)Spring
- Spring+Struts+Hibernate 簡介(轉)Spring
- Spring雜談 | 從橋接方法到JVM方法呼叫Spring橋接JVM
- Spring Cloud 純乾貨,從入門到實戰SpringCloud
- 從webwork2.2應用到struts2的移植看webwork2.x和struts2的區別Web