帮忙解决数据库联接问题 谢谢
<%@ page contentType="text/html; charset=GB2312" %><%@ page import="java.sql.*" %>
<%@ page language="java" %>
<%!
String searchdingdanid=null;
String searchdingdanriqi=null;
String searchkehuname=null;
String searchrenname=null;
String searchphone=null;
String searchjiaohuoriqi=null;
String searchhuopingmingchen=null;
String searchhuopingshuliang=null;
String searchhuopingdanjia=null;
String searchhuopingjine=null;
String searchxiaoshuoyuan=null;
int PageSize=1;//一页显示一个
int ShowPage=1;//页数初始
int RowCount=0;//Resultset后的笔数
int PageCount=0;//Resultset后的页数
Connection con=null;//数据库连接
Statement stmt=null;//指针(让指针可以移动用)
ResultSet rs=null; //结果集指针
%>
<%
searchdingdanid=request.getParameter("dingdanid");
searchdingdanriqi=request.getParameter("dingdanriqi");
searchkehuname=request.getParameter("kehuname");
searchrenname=request.getParameter("renname");
searchphone=request.getParameter("phone");
searchjiaohuoriqi=request.getParameter("jiaohuoriqi");
searchhuopingmingchen=request.getParameter("huopingmingchen");
searchhuopingshuliang=request.getParameter("huopingshuliang");
searchhuopingdanjia=request.getParameter("huopingdanjia");
searchhuopingjine=request.getParameter("huopingjine");
searchxiaoshuoyuan=request.getParameter("xiaoshuoyuan");
String sql="select * from xsdd";
if(!searchdingdanid.equals(""))
{
sql+="where xsdd_dh='"+searchdingdanid+"'";
}
else
{
sql+="where xsdd_dh like '%'";
}
if(!searchdingdanriqi.equals(""))
{
sql+="where xsdd_ddcsrq='"+searchdingdanriqi+"'";
}
if(!searchkehuname.equals(""))
{
sql+="where xsdd_khmc='"+searchkehuname+"'";
}
if(!searchrenname.equals(""))
{
sql+="where xsdd_lxr='"+searchrenname+"'";
}
if(!searchphone.equals(""))
{
sql+="where xsdd_lxrdh='"+searchphone+"'";
}
if(!searchjiaohuoriqi.equals(""))
{
sql+="where xsdd_jhq='"+searchjiaohuoriqi+"'";
}
if(!searchhuopingmingchen.equals(""))
{
sql+="where xsdd_hpmc='"+searchhuopingmingchen+"'";
}
if(!searchhuopingshuliang.equals(""))
{
sql+="where xsdd_hpsl='"+searchhuopingshuliang+"'";
}
if(!searchhuopingdanjia.equals(""))
{
sql+="where xsdd_hpdj='"+searchhuopingdanjia+"'";
}
if(!searchhuopingjine.equals(""))
{
sql+="where xsdd_hpje='"+searchhuopingjine+"'";
}
if(!searchxiaoshuoyuan.equals(""))
{
sql+="where xsdd_hpxsy='"+searchxiaoshuoyuan+"'";
}
%>
<%
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:shujuku");
stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
System.out.println( sql );
rs = stmt.executeQuery( sql ); //建立ResultSet(结果集)对象,并执行SQL语句
rs.last(); //将指标移至最后一笔记录
RowCount = rs.getRow(); //取得ResultSet中记录的笔数
//计算显示的页数
PageCount = ((RowCount % PageSize) == 0 ?
(RowCount/PageSize) : (RowCount/PageSize)+1);
%>
<html>
<head>
<title>查询结果</title>
</head>
<body>
<center>
<font> <size =5 color=blue>查询结果</font>
</center>
<br>
<hr>
<br>
<center>
<br>
<%
String ToPage = request.getParameter("ToPage");//topage后面定义
if(ToPage != null) //判断是否可正确取得ToPage参数
{
ShowPage = Integer.parseInt(ToPage); //取得指定显示的分页页数
if(ShowPage > PageCount) //下面的if语句将判断用户输入的页数是否正确
{
ShowPage = PageCount; //判断指定页数是否大于总页数, 是则设置显示最后一页
}
else if(ShowPage <= 0)
{
ShowPage = 1; //若指定页数小于0, 则设置显示第一页的记录
}
}
rs.absolute((ShowPage - 1) * PageSize + 1); //计算欲显示页的第一笔记录位置
%>
<H3>当前在第<FONT SIZE = 4 COLOR = red>
<%= ShowPage %></FONT>笔, 共
<FONT SIZE = 4 COLOR = red>
<%= PageCount %></FONT>笔</H3>
<BR>
<%
for(int i = 1; i <= PageSize; i++)//for循环显示
{
%>
<table border=1 bordercolor=RoyaBlue bgcolor=lightblue>
<tr><td bgcolor=LightYellow width=100>
<b>序号</b></td>
<td width=100><b><%="i"%>
</b></td>
<td bgcolor=LightYellow width=100>
<b>销售定单号</b>
<td width=100><b><%=rs.getString("baojiaid")%></b></td>
</tr>
</table><br>
<%if(!rs.next())
break;//到最后一页跳出
}
%>
<TABLE>
<TR valign=baseline align=center>
<%
//判断目前所在分页是否为第一页,
//不是则显示到第一页与上一页的超链接
if(ShowPage != 1)
{
//下面建立的各超链接将链接至自己,
//并将欲显示的分页以ToPage参数传递给自己
%>
<TD Width=150>
<A Href=baojia.jsp?ToPage=<%= 1 %>>到第一笔</A>
</TD>
<TD Width=150>
<A Href=Pages.jsp?ToPage=<%= ShowPage - 1 %>>到上一笔</A>
</TD>
<%
}
//判断目前所在分页是否为最后一页,
//不是则显示到最后一页与下一页的超链接
if(ShowPage != PageCount)
{
//下面建立的各超链接将链接至自己,
//并将欲显示的分页以ToPage参数传递自己
%>
<TD Width=150>
<A Href=baojia.jsp?ToPage=<%= ShowPage + 1%>>到下一笔</A>
</TD>
<TD Width=150>
<A Href=baojia.jsp?ToPage=<%= PageCount %>>到最后一笔</A>
</TD>
<%
rs.close(); //关闭ResultSet对象
stmt.close(); //关闭Statement对象
con.close(); //关闭数据库链接对象
}
%>
<TD Width=150>
<FORM action=baojia.jsp method=POST>
到
<INPUT type="text" name=ToPage style="HEIGHT: 25px; WIDTH: 40px"
value=<%= ShowPage%> > 笔
</FORM></TD></TR>
</TABLE>
</CENTER>
</BODY>
</HTML>
搜索更多相关主题的帖子:
联接 数据库
----------------解决方案--------------------------------------------------------
究竟是什么问题呀
太忙了,没有时间看完代码了
你说的连接问题,我看了一下,好象没有问题呀
你能吧你的错误,贴出来吗?
你用的是什么数据库
连接的时候不要用户名与密码吗?
[此贴子已经被作者于2005-5-26 12:30:17编辑过]
----------------解决方案--------------------------------------------------------
靠,出了一个错,搞的一些东西不更新了
这个论坛怎么搞的哟
----------------解决方案--------------------------------------------------------