strSQL="select * from guestbook where title like '%"+ search_title +"%'";//search_title就是那个搜索的变量名
sqlRst = sqlStmt.executeQuery(strSQL);.....

解决方案 »

  1.   

    goodflash(another) 大侠:
    我也知道sql语句这么写,但我不知道这句话加在哪里,大侠见笑了!!
      

  2.   

    部分代码:<%@ page contentType="text/html;charset=gb2312"%>   
    <%@ page import="java.sql.*"%>
    <%@ page import="java.util.*"%>
    <%@ include file="../inc/config.inc"%>
    <jsp:useBean id="dbconn" scope="page" class="livenet.denis" />
    <link rel="stylesheet" type="text/css" href="../inc/forAll.css">
    <%
    int pageno;
    String temp_pageno=request.getParameter("page");
    if (temp_pageno==null){ pageno=1;}
    else{pageno=java.lang.Integer.parseInt(temp_pageno);}
    %><html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <meta name="GENERATOR" content="Microsoft FrontPage 4.0">
    <meta name="ProgId" content="FrontPage.Editor.Document">
    <title>品牌天地</title>
    <link rel="stylesheet" type="text/css" href="../include/forAll.css">
    </head>
    <%String brand_name=request.getParameter("brand_name");String sqlstr;
    if (brand_name==null){
      sqlstr="select * from brand_class order by commend desc";
    }else {
      sqlstr="select * from brand_class where brand_name like '%" + brand_name + "%' order by commend desc";
    }
    ResultSet rs=dbconn.executeQuery(sqlstr);if (rs.next()){%><% //变量声明 java.sql.Connection sqlCon; //数据库连接对象 java.sql.Statement sqlStmt; //SQL语句对象 
    java.lang.String strCon; //数据库连接字符串 
    int intPageSize; //一页显示的记录数 int intRowCount; //记录总数 int intPageCount; //总页数 int intPage; //待显示页码 java.lang.String strPage; int i,j,k; //设置一页显示的记录数 intPageSize = 10; //取得待显示页码 strPage = request.getParameter("page"); if(strPage==null){//表明在QueryString中没有page这一个参数,此时显示第一页数据 intPage = 1; } else{//将字符串转换成整型 intPage = java.lang.Integer.parseInt(strPage); 
    if(intPage<1) intPage = 1; }String sqlstr_count;
    if (brand_name==null){
      sqlstr_count="select count(*) from brand_class";
    }else {
      sqlstr_count="select count(*) from brand_class where brand_name like '%" + brand_name + "%'";
    }
    ....