Object userUID=session.getAttribute("USERID")
String uid=""
if(userUID!=null)
{
uid=(String)userUID
}
else
{ response.sendRedirect("../Public/loseSession.jsp")}
try
{
String today=DateUtils.getInstance().getToday()
String userIP=request.getRemoteAddr()
String sql=""
String getPage=request.getParameter("toPage")
sql=cu.exchange(request.getParameter("sql"))if (sql==null||sql.equals("")){
String getDepId=""
String getPoliticalPosition=""
String getTechnicalPosition=""
String getPoliticalLevel=""
String getTechnicalLevel=""
String getDegreeCode=""
String getGrade=""
String getLongevity=""String getAllowance=""
long depId=0
long degreeCode=0
long politicalPosition=0
long technicalPosition=0
long politicalLevel=0
long technicalLevel=0
long grade=0
long longevity=0
long allowance=0
String[] postID=null
String post=""
String userID=""
String userName=""
String address=""
getDepId=request.getParameter("depId")
depId=Long.parseLong(getDepId.trim())getDegreeCode=request.getParameter("degreeCode")
if (getDegreeCode!=null) {
degreeCode=Long.parseLong(getDegreeCode.trim())
}
getPoliticalPosition=request.getParameter("politicalPosition")
if (getPoliticalPosition!=null) {
politicalPosition=Long.parseLong(getPoliticalPosition.trim())
}
post=request.getParameter("post")
if(post!=null&&post.trim().equals("1"))
postID=request.getParameterValues("dyourlocation")
getTechnicalPosition=request.getParameter("technicalPosition")if (getTechnicalPosition!=null) {
technicalPosition=Long.parseLong(getTechnicalPosition.trim())
}
getPoliticalLevel=request.getParameter("politicalLevel")if (getPoliticalLevel!=null) {politicalLevel=Long.parseLong(getPoliticalLevel.trim())
}getTechnicalLevel=request.getParameter("technicalLevel")if (getTechnicalLevel!=null) {
technicalLevel=Long.parseLong(getTechnicalLevel.trim())
}getGrade=request.getParameter("grade")if (getGrade!=null) {
grade=Long.parseLong(getGrade.trim())
}getLongevity=request.getParameter("longevity")if (getLongevity!=null) {
longevity=Long.parseLong(getLongevity.trim())
}getAllowance=request.getParameter("allowance")
if (getAllowance!=null) {
allowance=Long.parseLong(getAllowance.trim())
}
userID=ParamUtils.getParameter(request,"userID")//用户代码
userName=ParamUtils.getParameter(request,"userName")
//用户名称
address=ParamUtils.getParameter(request,"address")
//得到要转入的页面sql="select org_user.* from org_user,org_detail where org_user.user_id=org_detail.user_id"
if (depId!=0)
{
sql=sql+" and org_user.department_id="+depId+""
}if (userID!=null&&userID!=""){
sql=sql+" and org_user.user_id='"+userID+"'"
}
if (userName!=null&&userName!="")
{
sql=sql+" and org_user.name like '%"+userName+"%'"
}if (address!=null&&address!="")
{
sql=sql+" and org_user.address like '%"+address+"%'"
}
if(post!=null&&!post.trim().equals("0"))
{
sql=sql+" and org_detail.post in ("
for(int i=0i<postID.lengthi++)
{
sql=sql+postID[i]
if(i!=(postID.length-1))
sql=sql+","
}
sql=sql+")"
}
if (degreeCode!=0)
{
sql=sql+" and org_detail.degree="+degreeCode+""
}
if (politicalPosition!=0)
{
sql=sql+" and org_detail.politicalPosition="+politicalPosition+""
}
if (technicalPosition!=0)
{
sql=sql+" and org_detail.technicalPosition="+technicalPosition+""
}
if (technicalPosition!=0)
{
sql=sql+" and org_detail.politicalLevel="+politicalLevel+""
}
if (grade!=0)
{
sql=sql+" and org_detail.grade="+grade+""
}
if (longevity!=0)
{
sql=sql+" and org_detail.longevity="+longevity+""
}
if(getAllowance!=null)
{
if (allowance==0||allowance==1)
{
sql=sql+" and org_detail.allowance="+allowance+""
}
}
}
User[] userList =null
userList=ur.complexSearch(sql)
log.addLog(1,1,1,uid,userIP,uid+"于("+today+")查询员工")int cnt=userList.length//总记录数
int pageSize=10//每页显示记录数
int curPage=1//当前页
int cntPage//总页数
int m=1if (cnt>0)
{
if (cnt%pageSize==0)
cntPage=cnt/pageSize
else
cntPage=cnt/pageSize+1
}
else
cntPage=0if (getPage==null)
{
getPage="1"
curPage=1
}
else
curPage=Integer.parseInt(getPage.trim())
%><form name="thisform" action="userSearchDel.jsp" method="post">
<table bgColor="#FFFFFF" border="1" borderColorDark="#ffffff" borderColorLight="#c0c0c0" cellSpacing="0" width="95%" cellpadding="4">
<tr height="25" align="center" bgcolor="#959595">
<td> </td>
<td><font color="#FFFFFF">姓名</font></td>
<td><font color="#FFFFFF">性别</font></td>
<td><font color="#FFFFFF">所在部门</font></td>
<td><font color="#FFFFFF">办公地址</font></td>
<td><font color="#FFFFFF">联系电话</font></td>
</tr>
<%
int u=1
for(int i=0i<cnti++)
{
//显示记录的起始位置
int j=(curPage-1)*pageSize
//显示记录的末位置
int k=curPage*pageSize
//只显示page_size条数据
if(m>j&&m<=k)
{
String userId=userList[i].getUserID()
String gender=userList[i].getGender()
String name=userList[i].getName()
String tel=userList[i].getTel()
String useAddress=userList[i].getAddress()
long dep_id=userList[i].getDepID()
String dname=dep.getName(userList[i].getDepID())
if(tel==null||tel.equals("null"))
tel=""
if(useAddress==null||useAddress.equals("null"))
useAddress=""
//判断没一行该输出的颜色
if((u%2)==0)
{
out.println("<tr bgcolor=#D7D7D7 onMouseOver=this.style.backgroundColor='#fcd4d7'onMouseOut=if(selectedItem!=this.id){this.style.backgroundColor='#D7D7D7'}>")
}
else
{
out.println("<tr onMouseOver=this.style.backgroundColor='#fcd4d7'onMouseOut=if(selectedItem!=this.id){this.style.backgroundColor='#FFFFFF'}>")
}
u++
%>
<td align=center><input type="checkbox" name="checkbox" id="CHK_+<%=userId%>" value="<%=userId%>"></td>
<td align=center>
<%
long departmentID=ur.getDepID(uid)
if(up.haveRight(uid,"USER_COMPLEXQUERY")==true)
{
%>
<a href="userAnalyze.jsp?userId=<%=userId%>&dep_id=<%=dep_id%>&toPage=<%=curPage%>"><font color="#330099">
<%
}
else if(up.haveRight(uid,"DEPARTMENT_PLATFORM")==true&&dep_id==departmentID)
{
%>
<a href="userAnalyze.jsp?userId=<%=userId%>&dep_id=<%=dep_id%>&toPage=<%=curPage%>"><font color="#330099">
<%
}
%>
<%=name%></font></a></td>
<%
if(gender.trim().equals("0"))
out.println("<td align=center>男</td>")
else
out.println("<td align=center>女</td>")
%>
<td align=center><a href="depintro.jsp?id=<%=dep_id%>&toPage=<%=curPage%>"><font color="#330099"><%=dname%></font></a></td>
<td align=center><%=useAddress%></td>
<td align=center><%=tel%></td>
</tr>
<%
}//end ifm++
}//end for
%>
<input type=hidden name="sql" value="<%=sql%>">
<input type=hidden name="page" value="<%=curPage%>">
</table>
</form>
<form name=pageform action="searchAction.jsp" method="post">
<table border="0" width="95%">
<tr>
<td align="center">第<%=curPage%>页/共<%=cntPage%>页</td>
<td align="left">
<img name="firstpage" src="../Image/btn_firstpage.gif" style="cursor:hand" onclick="pageClick(1)" <%=curPage>1?" ":"disabled"%>>
<img name="prepage" src="../Image/btn_prepage.gif" style="cursor:hand" onclick="pageClick(<%=curPage-1%>)" <%=curPage>1?" ":"disabled"%>>
<img name="nextpage" src="../Image/btn_nextpage.gif" style="cursor:hand" onclick="pageClick(<%=curPage+1%>)" <%=curPage<cntPage?" ":"disabled"%>>
<img name="lastpage" src="../Image/btn_lastpage.gif" style="cursor:hand" onclick="pageClick(<%=cntPage%>)" <%=curPage<cntPage?" ":"disabled"%>>
</td>
<td align=left width=55%>
到第<input type="text" name="goPage" size="4">页
<img border="0" src="../Image/icon_search.gif" style="cursor:hand" onclick="aPage()">
</td>
</tr><tr>
<td colspan="3" valign="middle" width="23%" align="right">
<%
if(up.haveRight(uid,"USER_MANAGE")==true)
{
%>
<img border="0" src="../Image/btn_delete.gif" style="cursor:hand" onclick="delUser()">
<%}%>
<img border="0" src="../Image/btn_return.gif" style="cursor:hand" onclick="back()">
</td>
<input type=hidden name="sql" value="<%=sql%>">
<input type=hidden name="toPage">
</td>
</tr>
</table>
</form>
<br>
<br>
</td>
</tr>
</table>
</td>
</tr>
</table>
<%
}//end else
}//end try
catch(Exception e)
{
out.println(e.getMessage())
}
%>
</td>
</tr>
</table>
上面的给出了jsp内嵌java的最初模式,现在一般是三层结构了即MVC结构,就这个例子我来给你解释下是怎么做的,java对连接数据库提供了统一的接口,各个数据库厂商根据提供的接口规范开发自己的连接方法顺序如下:1、用Class.forName()方法加载驱动:Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance()黑体部分为数据库厂商自己开发的驱动。2、定义好连接数据库的url地址,连接串String url="jdbc:microsoft:sqlserver://localhost:1433DatabaseName=pubs"黑体部分为固定写法不用理会。回到你最初的问题,如何创建数据库,这里你可以去baidu下每个数据库创建的方法,一般数据库安装的时候都有默认的数据库名,和对应的系统管理员工号和密码,DatabaseName=pubs这里说明sql serv 2000中建立了一个名字叫pubs的数据库jdbc:microsoft:sqlserver://localhost:1433固定写法唯一不同的是1433端口号,可能你在安装sql serv 2000的时候改变了该端口号为1500那么这里就应该为jdbc:microsoft:sqlserver://localhost:15003、定义好DatabaseName=pubs的登录用户名和密码 String user="sa"用户名String password=""密码4、创建Connection对象,通过调用DriverManager.getConnection方法获得。 Connection conn= DriverManager.getConnection(url,user,password)黑体部分就是你定义好的连接串,用户名,密码,不可改变顺序。到这里为止数据库就连接上了,但是连接好了数据库还要做点什么,比如打印出来,接下看。5、通过获得的Connection对象conn创建Statement 对象stmtStatement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE)黑体部分是定义ResultSet的一些属性的,具体含义可以参考JDK的api。6、定义好你准备取得数据的sql语句,比如下面 select * from test说明想从test表中取得所有的数据,关于sql语句可以去查找相关数据库资料。 String sql="select * from test"定义好语句后,就用上一步创建好的Statement 对象stmt来执行这个sql语句,并返回一个ResultSet对象。
ResultSet rs=stmt.executeQuery(sql)执行完这步后rs中已经取得了test表所有的数据,那么接下来要展现在网页上。7、rs.next()对你取得的记录集做一个循环直到没有值为止,rs.getString(1)代表你test表中的第一个字段rs.getString(2)代表你test中的第二个字段,如果还有更多字段可以继续rs.getString(3)..rs.getString(N) while(rs.next()) {%>
您的第一个字段内容为:<%=rs.getString(1)%>
您的第二个字段内容为:<%=rs.getString(2)%>
<%}%>8、当所有数据展现完毕,调用close()方法将所有资源关闭。 rs.close()
stmt.close()
conn.close()回顾下大致过程:加载驱动 Class.forName()定义好相关的数据,调用DriverManager.getConnection(driver,user,password)获得一个数据库连接conn通过conn创建Statement对象stmt,conn.createStatement()通过stmt执行定义好的sql语句获得数据集ResultSet rs=stmt.executeQuery(“select * from test”)通过rs.next()方法循环遍历数据集的数据,通过rs.getString(1)获得第一条数据的第一个字段内容,这里要注意的是getString是对应数据库是字符类型,如果test表的第一个字段不是字符类型则用rs.getInt(1)获得。展现完毕后关闭所有资源conn stmt rs close方法。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)