📄 fenyedao.java
字号:
package com.zjy.struts.mypackage;
import java.sql.*;
import com.zjy.struts.mybean.*;
public class FenyeDao {
public Connection con = null;
public Statement stmt = null;
public ResultSet rs = null;
Fenye fy = new Fenye();
public FenyeDao() {
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver")
.newInstance();
String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=luntan";
String user = "sa";
String password = "";
con = DriverManager.getConnection(url, user, password);
} catch (Exception e) {
// TODO: handle exception
}
}
public Fenye selectZhutie(String s) {
zalllist();
fy.setAllpage((fy.getAlllist() % fy.getShowlist()) == 0 ? (fy
.getAlllist() / fy.getShowlist()) : (fy.getAlllist()
/ fy.getShowlist() + 1));
try {
int sp = Integer.parseInt(s);
fy.setShowpage(sp);
} catch (Exception e) {
// TODO: handle exception
fy.setShowpage(1);
}
setPage();
return fy;
}
public Fenye selectHuitie(String s, int id) {
fy.setId(id);
halllist(id);
int ap = (fy.getAlllist() % fy.getShowlist()) == 0 ? (fy.getAlllist() / fy
.getShowlist())
: (fy.getAlllist() / fy.getShowlist() + 1);
if (ap == 0) {
fy.setAllpage(1);
} else {
fy.setAllpage(ap);
}
try {
int sp = Integer.parseInt(s);
fy.setShowpage(sp);
} catch (Exception e) {
// TODO: handle exception
fy.setShowpage(1);
}
setPage();
return fy;
}
public void zalllist() {
String sql = "select count(*) from zhutie";
try {
stmt = con.createStatement();
rs = stmt.executeQuery(sql);
if (rs.next()) {
fy.setAlllist(rs.getInt(1));
} else {
fy.setAlllist(0);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
rs.close();
stmt.close();
con.close();
} catch (Exception e) {
// TODO: handle exception
}
}
}
public void halllist(int id) {
String sql = "select count(*) from huitie where parentid=" + id;
try {
stmt = con.createStatement();
rs = stmt.executeQuery(sql);
// rs.last();
if (rs.next()) {
fy.setAlllist(rs.getInt(1));
} else {
fy.setAlllist(0);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
rs.close();
stmt.close();
con.close();
} catch (Exception e) {
// TODO: handle exception
}
}
}
public void setPage() {
fy.setFristpage(1);
fy.setLastpage(fy.getAllpage());
if (fy.getShowpage() <= 1) {
if (fy.getAllpage() == 1) {
fy.setPreviouspage(1);
fy.setNextpage(1);
} else {
fy.setPreviouspage(1);
fy.setNextpage(2);
}
} else if (fy.getShowpage() >= fy.getAllpage()) {
fy.setPreviouspage(fy.getAllpage() - 1);
fy.setNextpage(fy.getAllpage());
} else {
fy.setPreviouspage(fy.getShowpage() - 1);
fy.setNextpage(fy.getShowpage() + 1);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -