📄 testdb.jsp
字号:
<%@ page contentType="text/html; charset=GBK" %>
<%@ page import="java.util.*"%>
<%@ page import="java.io.*"%>
<%@ page import="java.sql.*"%>
<%@ page import="tool.TableFormat"%>
<html>
<head>
<title>
连接测试表格
</title>
</head>
<body>
<%
Connection con=null;
Statement stmt=null;
ResultSet rs=null;
//PrintWriter p = new PrintWriter(out);
TableFormat TF=new TableFormat(out,request);
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
String conStr="jdbc:oracle:thin:@192.168.202.108:1521:dbname";
con=DriverManager.getConnection(conStr,"username","password");
stmt=con.createStatement();
String s_sql="select * from swduser.swddt002";
TF.PageSize=5;
TF.Direction="testdb.jsp";
TF.url="testdb.jsp";
TF.ifpage=false;
TF.IfOrder=false;
TF.ifdetail=false;
TF.ifdel=false;
TF.AddCol("编号",80,"dnmenuid",TF.M_NUMBER);
TF.AddCol("信息",250,"dcmessage",TF.M_CHAR);
TF.AddCol("图标",200,"",TF.M_CHAR);
TF.AddCol("归类",100,"dnsortid",TF.M_NUMBER);
//TF.AddCol("删除",40,"",TF.M_CHAR);
String direction=request.getParameter("Direction");
if(direction==null)
direction="desc";
String orderby=request.getParameter("OrderBy");
if(orderby==null)
orderby="dnmenuid";
TF.OrderBy=orderby;
TF.Direction=direction;
int curpage=1;
String s_curpage=request.getParameter("CurPage");
if(s_curpage==null)
curpage=1;
else
curpage=Integer.parseInt(s_curpage);
TF.OrderBy=orderby;
String sql_count="select count(*) from ("+s_sql+")";
rs=stmt.executeQuery(sql_count);
if(rs.next())
{
int count=rs.getInt(1);
if(count%TF.PageSize==0)
TF.PageNum=count/TF.PageSize;
else
TF.PageNum=count/TF.PageSize+1;
if(TF.PageNum==0)
TF.CurPage=0;
}
else
{
out.print("<p align=right>没有任何数据</p>");
}
rs.close();
if(TF.PageNum>0)
{
s_sql="select a,dnmenuid,dcmessage,dnsortid,dcicon";
s_sql+=" from (select rownum as a,dnmenuid,dcmessage,dnsortid,dcicon from ";
s_sql+="swduser.swddt002 order by "+orderby+" "+direction+")";
s_sql="select * from("+s_sql+") where a>"+((curpage-1)*TF.PageSize);
s_sql+=" and a<="+(curpage*TF.PageSize);
//out.print("1111111111111111111111111111<br>");
rs=stmt.executeQuery(s_sql);
while(rs.next()){
String[] rowdata=new String[4];
rowdata[0]=rs.getString("dnmenuid");
rowdata[1]=rs.getString("dcmessage");
rowdata[2]=rs.getString("dcicon");
rowdata[3]=rs.getString("dnsortid");
TF.AddRow(rowdata,"");
}
}
TF.Print();
stmt.close();stmt=null;
con.close();
con=null;
}catch(Exception e){
out.print(e);
}
%>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -