数据库jsp查询语句怎么写(jsp实现数据库查询)

本文目录一览:

jsp数据库查询

sql = “select * from my_table where nian_fen”+kai_shi_nian_fen +”and nian_fen”+jie_shu_nian_fen;

你这样试试,引号内是你要穿给sql的最终值,而显然kai_shi_nian_fen 不是你要真正加到sql中的,你需要的是他的值,所以要放在引号外面,用加号链接。

jsp查询数据库里面的信息怎么写代码啊

jsp先加载你数据库的驱动,连接数据库(不同数据库不一样),然后再写sql语句,再执行sql,再通过rs集,把rs结果集读出显示在jsp页面

jsp查询数据库代码

这种方法并不是很常用,只是页面的相关操作,代码太多,所以中间省略了部分%

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!=nullpost.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!=nulluserID!=””){

sql=sql+” and org_user.user_id='”+userID+”‘”;

}

if (userName!=nulluserName!=””)

{

sql=sql+” and org_user.name like ‘%”+userName+”%'”;

}if (address!=nulladdress!=””)

{

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=0;ipostID.length;i++)

{

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=1; if (cnt0)

{

if (cnt%pageSize==0)

cntPage=cnt/pageSize;

else

cntPage=cnt/pageSize+1;

}

else

cntPage=0; if (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

tdfont color=”#FFFFFF”姓名/font/td

tdfont color=”#FFFFFF”性别/font/td

td font color=”#FFFFFF”所在部门/font/td

td font color=”#FFFFFF”办公地址/font/td

tdfont color=”#FFFFFF”联系电话/font/td

/tr

%

int u=1;

for(int i=0;icnt;i++)

{

//显示记录的起始位置

int j=(curPage-1)*pageSize;

//显示记录的末位置

int k=curPage*pageSize;

//只显示page_size条数据

if(mjm=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=centerinput 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”)==truedep_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=centera 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 if m++;

}//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)” %=curPage1?” “:”disabled”%

img name=”prepage” src=”../Image/btn_prepage.gif” style=”cursor:hand” onclick=”pageClick(%=curPage-1%)” %=curPage1?” “:”disabled”%

img name=”nextpage” src=”../Image/btn_nextpage.gif” style=”cursor:hand” onclick=”pageClick(%=curPage+1%)” %=curPagecntPage?” “:”disabled”%

img name=”lastpage” src=”../Image/btn_lastpage.gif” style=”cursor:hand” onclick=”pageClick(%=cntPage%)” %=curPagecntPage?” “:”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

/trtr

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页面,具体怎么写代码

sql 语句”SELECT COUNT(字段名) FORM 表名 WHERE 查询条件;”

得到的数 int a = request.setAttribute(“num”,变量名);

然后 jsp上要显示的位置 %=request.getAttribute(“num”,变量名); %

jsp页面中,条件查询要怎么做

示例:

JSP 页面中:input name = “username”

后台 :String sql = “select * from user where username =?”;//从用户表中查询指定用户名的数据

取得文本框中的值:String name = requset.getParameter(“username”);

然后取得connection对象 conn

Preparestatement pstmt = conn.preparestatement();

pstmt.setString(1,name);//拼接sql语句成为:select * from user where username =(name的值);

最后执行sql语句

jsp页面在数据库查询

String mysql=”select * from task where 1=1″;

if(request.getParameter(“taskdate”)!=null!request.getParameter(“taskdate”).equals(“”))

{

mysql=mysql+” and taskdate=”+request.getParameter(“taskdate”);

}

if(request.getParameter(“tasktype”)!=null!request.getParameter(“tasktype”).equals(“”))

{

mysql=mysql+” and tasktype=”+request.getParameter(“tasktype”);

}

if(request.getParameter(“taskstate”)!=null!request.getParameter(“taskstate”).equals(“”))

{

mysql=mysql+” and tasktype=”+request.getParameter(“taskstate”);

}

if(request.getParameter(“station”)!=null!request.getParameter(“station”).equals(“”))

{

mysql=mysql+” and station=”+request.getParameter(“station”);

}

假设你的完成日期、任务类型、任务状态和分站分别为taskdate、tasktype、taskstate和station.

用jsp的话,应该这些就可以了。mysql就是你要的SQL语句。

原创文章,作者:HQNQV,如若转载,请注明出处:https://www.506064.com/n/317327.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
HQNQVHQNQV
上一篇 2025-01-11 16:27
下一篇 2025-01-11 16:27

相关推荐

  • Python3支持多行语句

    Python3是一种高级编程语言,开发人员可以轻松地使用该语言编写简单到复杂的代码。其中Python3支持多行语句,方便开发人员编写复杂的代码,提高代码的可读性和可维护性。 一、使…

    编程 2025-04-29
  • Python 常用数据库有哪些?

    在Python编程中,数据库是不可或缺的一部分。随着互联网应用的不断扩大,处理海量数据已成为一种趋势。Python有许多成熟的数据库管理系统,接下来我们将从多个方面介绍Python…

    编程 2025-04-29
  • openeuler安装数据库方案

    本文将介绍在openeuler操作系统中安装数据库的方案,并提供代码示例。 一、安装MariaDB 下面介绍如何在openeuler中安装MariaDB。 1、更新软件源 sudo…

    编程 2025-04-29
  • Python for循环语句打印九九乘法表

    本篇文章将详细介绍如何使用Python的for循环语句打印九九乘法表。打印九九乘法表是我们初学Python时经常练习的一项基础操作,也是编写Python程序的基本能力之一。 1、基…

    编程 2025-04-29
  • Python中while语句和for语句的区别

    while语句和for语句是Python中两种常见的循环语句,它们都可以用于重复执行一段代码。然而,它们的语法和适用场景有所不同。本文将从多个方面详细阐述Python中while语…

    编程 2025-04-29
  • Python中自定义函数必须有return语句

    自定义函数是Python中最常见、最基本也是最重要的语句之一。在Python中,自定义函数必须有明确的返回值,即必须要有return语句。本篇文章将从以下几个方面对此进行详细阐述。…

    编程 2025-04-29
  • 数据库第三范式会有删除插入异常

    如果没有正确设计数据库,第三范式可能导致删除和插入异常。以下是详细解释: 一、什么是第三范式和范式理论? 范式理论是关系数据库中的一个规范化过程。第三范式是范式理论中的一种常见形式…

    编程 2025-04-29
  • Python中升序排列的if语句

    本文将为大家介绍Python中升序排列的if语句。首先,我们来看一下如何实现。 if a > b: a, b = b, a if b > c: b, c = c, b …

    编程 2025-04-29
  • leveldb和unqlite:两个高性能的数据库存储引擎

    本文将介绍两款高性能的数据库存储引擎:leveldb和unqlite,并从多个方面对它们进行详细的阐述。 一、leveldb:轻量级的键值存储引擎 1、leveldb概述: lev…

    编程 2025-04-28
  • Python怎么导入数据库

    Python是一种高级编程语言。它具有简单、易读的语法和广泛的库,让它成为一个灵活和强大的工具。Python的数据库连接类型可以多种多样,其中包括MySQL、Oracle、Post…

    编程 2025-04-28

发表回复

登录后才能评论