//调用的bean代码
package user;import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;public class SJYHDB {
private Connection con;
private Statement stm;
private ResultSet rs;
private String classname="oracle.jdbc.driver.OracleDriver";
private String url="jdbc:oracle:thin:@此处隐去IP等信息"; private int num_per=8;
private int num_rs=0;
private int pages_all=0;
private int page_current=1;
public SJYHDB(){}
public Connection getCon(){
try{
Class.forName(classname);
}
catch(ClassNotFoundException e){
e.printStackTrace();
}
try{
con=DriverManager.getConnection(url,"wj","123456");
}
catch(Exception e){
e.printStackTrace(System.err);
con=null;
}
return con;
}
public Statement getStm(){
try{
con=getCon();
stm=con.createStatement();
}catch(Exception e){e.printStackTrace(System.err);}
return stm;
}
public Statement getStmed(){
try{
con=getCon();
stm=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
}catch(Exception e){e.printStackTrace(System.err);}
return stm;
}
//前台把页数传近来,计算总记录数和页数
public void setPageInfo(int page){
String sql="select id,username from account where s='1'";
try{
stm=getStmed();
rs=stm.executeQuery(sql);
rs.last(); //将记录指针移动到最后一条记录;
this.num_rs=rs.getRow(); //获取当前指针所指记录的行号,即总记录数
this.pages_all=(num_rs%num_per==0)?(num_rs/num_per):(num_rs/num_per)+1; //计算出总页数;
if(page<1)
this.page_current=1; //如果由参数传递过来的当前页数值小于1,则将当前页数设置为1;
else if(page>this.pages_all)
this.page_current=this.pages_all; //如果由参数传递过来的当前页数值大于总页数,则将当前页数设置为总页数;
else
this.page_current=page;
}
catch(SQLException e){e.printStackTrace();}
}
/**
* @return
*/
public ResultSet getPageRs(){
int idnum=(this.page_current-1)*this.num_per;
String sql="";
//当页数小于1时执行
if(this.page_current==1)
sql="select id,username,realname,tel,email,address,to_char(recordtm,'yyyy-mm-dd hh24:mi:ss') as r from account where rownum<='"+this.num_per+"' and s='1' order by recordtm desc";
//当页数大于1时执行,这边的SQL应该如何写才能实现每8条就分页??请朋友帮忙看看
else
sql="select id,username,realname,tel,email,address,recordtm,s from (select id,username,realname,tel,email,address,recordtm,rownum as rn,s from (select id,username,realname,tel,email,address,recordtm,s from account where s='1') a where rownum <= 8 and s='1') where rn >= 2 and s='1'";
//数据表中字段s为标志位
System.out.println("sql:::"+sql);
try{
rs=stm.executeQuery(sql);
}
catch(Exception e){e.printStackTrace();}
return rs;
}
public int getNumper(){
return this.num_per;
}
public int getNumrs(){
return this.num_rs;
}
public int getPagesall(){
return this.pages_all;
}
public int getPagecurrent(){
return this.page_current;
}
public void closed(){
try{
if(rs!=null)rs.close();
}
catch(Exception e){e.printStackTrace();}
try{
if(stm!=null)stm.close();
}
catch(Exception e){e.printStackTrace();}
try{
if(con!=null)con.close();
}
catch(Exception e){e.printStackTrace();}
}
}
请朋友结合我的代码给我改下,我试了很久了,老是报错
多谢了。
package user;import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;public class SJYHDB {
private Connection con;
private Statement stm;
private ResultSet rs;
private String classname="oracle.jdbc.driver.OracleDriver";
private String url="jdbc:oracle:thin:@此处隐去IP等信息"; private int num_per=8;
private int num_rs=0;
private int pages_all=0;
private int page_current=1;
public SJYHDB(){}
public Connection getCon(){
try{
Class.forName(classname);
}
catch(ClassNotFoundException e){
e.printStackTrace();
}
try{
con=DriverManager.getConnection(url,"wj","123456");
}
catch(Exception e){
e.printStackTrace(System.err);
con=null;
}
return con;
}
public Statement getStm(){
try{
con=getCon();
stm=con.createStatement();
}catch(Exception e){e.printStackTrace(System.err);}
return stm;
}
public Statement getStmed(){
try{
con=getCon();
stm=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
}catch(Exception e){e.printStackTrace(System.err);}
return stm;
}
//前台把页数传近来,计算总记录数和页数
public void setPageInfo(int page){
String sql="select id,username from account where s='1'";
try{
stm=getStmed();
rs=stm.executeQuery(sql);
rs.last(); //将记录指针移动到最后一条记录;
this.num_rs=rs.getRow(); //获取当前指针所指记录的行号,即总记录数
this.pages_all=(num_rs%num_per==0)?(num_rs/num_per):(num_rs/num_per)+1; //计算出总页数;
if(page<1)
this.page_current=1; //如果由参数传递过来的当前页数值小于1,则将当前页数设置为1;
else if(page>this.pages_all)
this.page_current=this.pages_all; //如果由参数传递过来的当前页数值大于总页数,则将当前页数设置为总页数;
else
this.page_current=page;
}
catch(SQLException e){e.printStackTrace();}
}
/**
* @return
*/
public ResultSet getPageRs(){
int idnum=(this.page_current-1)*this.num_per;
String sql="";
//当页数小于1时执行
if(this.page_current==1)
sql="select id,username,realname,tel,email,address,to_char(recordtm,'yyyy-mm-dd hh24:mi:ss') as r from account where rownum<='"+this.num_per+"' and s='1' order by recordtm desc";
//当页数大于1时执行,这边的SQL应该如何写才能实现每8条就分页??请朋友帮忙看看
else
sql="select id,username,realname,tel,email,address,recordtm,s from (select id,username,realname,tel,email,address,recordtm,rownum as rn,s from (select id,username,realname,tel,email,address,recordtm,s from account where s='1') a where rownum <= 8 and s='1') where rn >= 2 and s='1'";
//数据表中字段s为标志位
System.out.println("sql:::"+sql);
try{
rs=stm.executeQuery(sql);
}
catch(Exception e){e.printStackTrace();}
return rs;
}
public int getNumper(){
return this.num_per;
}
public int getNumrs(){
return this.num_rs;
}
public int getPagesall(){
return this.pages_all;
}
public int getPagecurrent(){
return this.page_current;
}
public void closed(){
try{
if(rs!=null)rs.close();
}
catch(Exception e){e.printStackTrace();}
try{
if(stm!=null)stm.close();
}
catch(Exception e){e.printStackTrace();}
try{
if(con!=null)con.close();
}
catch(Exception e){e.printStackTrace();}
}
}
请朋友结合我的代码给我改下,我试了很久了,老是报错
多谢了。
解决方案 »
- 在给学校做一个人事管理系统,人事处那边要求能自定义字段,求问如何解决?
- 连接sqlServer 2005时出错,怎么解决啊?
- 不知道是什么问题,高手请进!
- 关于NetBeans中使用JBoss服务的问题!请高手解答
- 谁能帮我解决这个问题(jsp导出EXCEL后打开汉字成乱码),多家分!!!!!
- 如何将全角字符转化成半角字符?
- 关于jsp中做分页的问题,请大家帮帮忙!
- 关于jsp中的文本框输入的东东怎样生成html页
- jbuilder怎末调试JavaBean呢?
- Hibernate自身关联添加数据,父节点ID怎么获得?在线等
- 后台增加信息时如何增加超链接
- 关于TOMCAT 5.0+JSP的问题!!!!!!!!
楼主【Geforce6600】截止到2008-06-23 16:05:58的历史汇总数据(不包括此帖):
发帖数:12 发帖分:420
结贴数:10 结贴分:370
未结数:2 未结分:50
结贴率:83.33 % 结分率:88.10 %
楼主加油
String sql =
"SELECT * FROM (select temp.*, ROWNUM rn FROM ("
+ sql_org
+ ") temp where ROWNUM <= " + idnum
+ ") where rn >" + (idnum - 8);
[*]The Oracle Hacker's Handbook: Hacking and Defending Oracle ebook free download
[*]Oracle PL/SQL for DBAs ebook free download
[*]Oracle PL/SQL Programming ebook free download
[*]Learning Oracle PL/SQL ebook free download
[*]Optimizing Oracle Performance ebook free download
[*]Oracle Database Foundations ebook free download
[*]Forecasting Oracle Performance ebook free download
[*]Mastering Oracle SQL ebook free download
[*]Perl for Oracle DBAs ebook free download
[*]Oracle PL/SQL by Example, Third Edition ebook free download
[*]Oracle Database 10g New Features ebook free download
[*]Oracle Database 10g:A Beginner's Guide ebook free download
[*]Oracle DBA SQL Quick Reference ebook free download
[*]Oracle High Performance Tuning for 9i and 10g ebook free download
[*]Oracle Database 10g INSIDER SOLUTIONS ebook free download
[*]Oracle Application Server 10g Web Development ebook free download
[*]Cost-Based Oracle Fundamentals ebook free download
[*]Oracle Data Warehousing and Business Intelligence Solutions ebook free download
[*]Oracle Applications DBA Field Guide ebook free download
[*]Expert Oracle Database Architecture: 9i and 10g Programming Techniques and Solutions ebook free download
[*]Oracle PL/SQL Language Pocket Reference, Fourth Edition ebook free download
[*]RMAN Recipes for Oracle Database 11g A Problem-Solution Approach ebook free download
[*]Oracle PL/SQL Language Pocket Reference, 2nd Edition ebook free download
[*]Oracle Wait Interface: A Practical Guide to Performance Diagnostics and Tuning ebook free download
[*]Oracle 11i E-Business Suite From the Front Lines ebook free download
[*]Using Oracle SQL Stored Outlines and Optimizer Plan Stability ebook free download
[*]Oracle Database 10g XML & SQL: Design, Build, & Manage XML Applications in Java, C, C++, & PL/SQL ebook free download
[*]Tuning Third-party Vendor Oracle systems Tuning when you can't touch the code ebook free download
[*]Relational Database Index Design and the Optimizers DB2, Oracle, SQL Server, et al. ebook free download