U
unixhost
Unregistered / Unconfirmed
GUEST, unregistred user!
目的做个JAVABEAN.
第一方法:获得5个字符串,存入数组,并返回此数组。
第二方法:从数组取出,根据条件生成SQL语句,并返回。
package diss;
import java.awt.*;
import javax.swing.JPanel;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.math.*;
public class strsqlpd {
private String getTj[] = new String[5];
private String strSql = null;
public String[] getTj(HttpServletRequest request, String tiaojian){
try{
int i;
for(i=0;i<5;i++)
getTj = request.getParameter(tiaojian);//request对象取得page的值
}
catch(Exception e){
System.out.println("delcolumn"+e.getMessage());
}
int i;
for(i=0;i<5;i++)
return getTj;//返回这个值。
}
public int strSql(String getTj[],int j){
try{
String s_tujing = getTj[0];
String s_year = getTj[1];
String s_nian = getTj[2];
String s_jilushu = getTj[3];
String p_jiansuoci = getTj[4].trim();
String s_jiansuoci = new String(p_jiansuoci.getBytes("iso8859-1"), "gb2312");
if(j==1)
{
strSql = "select lwtm,lwzz,kanming,nian,qishu,yuanwen from lwmx a";
if (s_tujing.compareTo("tm")==0)
{
strSql = strSql + " Where a.lwtm Like '%" + s_jiansuoci + "%' ";
}
if (s_tujing.compareTo("zz")==0)
{
strSql=strSql + ",lwzz b,zzlwlj c Where a.lwbh=c.lwbh And c.zzbh=b.zzbh And b.zzxm Like '%"+s_jiansuoci+"%' ";
}
if (s_tujing.compareTo("bm")==0)
{
strSql=strSql + ",bm b,bmlwlj c Where a.lwbh=c.lwbh And c.bmbh=b.bmbh And b.zzbm Like '%"+s_jiansuoci+"%' ";
}
if (s_tujing.compareTo("xk")==0)
{
strSql=strSql + ",lwxk b,xklwlj c Where a.lwbh=c.lwbh And c.xkbh=b.xkbh And b.xk Like '%"+s_jiansuoci+"%' ";
}
if (s_tujing.compareTo("gjc")==0)
{
strSql=strSql + ",gjc b,gjclwlj c Where a.lwbh=c.lwbh And c.gjcbh=b.gjcbh And b.gjc Like '%"+s_jiansuoci+"%' ";
}
if(!s_year.equals("")&&
!s_nian.equals(""))
{
strSql=strSql + " And a.nian>="+s_year+" And a.nian<="+s_nian;
}
}
if(j==2)
{
strSql = "select count(*) as t from lwmx a";
if (s_tujing.compareTo("tm")==0)
{
strSql = strSql + " Where a.lwtm Like '%" + s_jiansuoci + "%' ";
}
if (s_tujing.compareTo("zz")==0)
{
strSql=strSql + ",lwzz b,zzlwlj c Where a.lwbh=c.lwbh And c.zzbh=b.zzbh And b.zzxm Like '%"+s_jiansuoci+"%' ";
}
if (s_tujing.compareTo("bm")==0)
{
strSql=strSql + ",bm b,bmlwlj c Where a.lwbh=c.lwbh And c.bmbh=b.bmbh And b.zzbm Like '%"+s_jiansuoci+"%' ";
}
if (s_tujing.compareTo("xk")==0)
{
strSql=strSql + ",lwxk b,xklwlj c Where a.lwbh=c.lwbh And c.xkbh=b.xkbh And b.xk Like '%"+s_jiansuoci+"%' ";
}
if (s_tujing.compareTo("gjc")==0)
{
strSql=strSql + ",gjc b,gjclwlj c Where a.lwbh=c.lwbh And c.gjcbh=b.gjcbh And b.gjc Like '%"+s_jiansuoci+"%' ";
}
if(!s_year.equals("")&&
!s_nian.equals(""))
{
strSql=strSql + " And a.nian>="+s_year+" And a.nian<="+s_nian;
}
}
return strSql;
}
catch(Exception e){
System.out.print("strSql");
}
return strSql;//返回字符串
}
public strsqlpd() {
}
}
第一方法:获得5个字符串,存入数组,并返回此数组。
第二方法:从数组取出,根据条件生成SQL语句,并返回。
package diss;
import java.awt.*;
import javax.swing.JPanel;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.math.*;
public class strsqlpd {
private String getTj[] = new String[5];
private String strSql = null;
public String[] getTj(HttpServletRequest request, String tiaojian){
try{
int i;
for(i=0;i<5;i++)
getTj = request.getParameter(tiaojian);//request对象取得page的值
}
catch(Exception e){
System.out.println("delcolumn"+e.getMessage());
}
int i;
for(i=0;i<5;i++)
return getTj;//返回这个值。
}
public int strSql(String getTj[],int j){
try{
String s_tujing = getTj[0];
String s_year = getTj[1];
String s_nian = getTj[2];
String s_jilushu = getTj[3];
String p_jiansuoci = getTj[4].trim();
String s_jiansuoci = new String(p_jiansuoci.getBytes("iso8859-1"), "gb2312");
if(j==1)
{
strSql = "select lwtm,lwzz,kanming,nian,qishu,yuanwen from lwmx a";
if (s_tujing.compareTo("tm")==0)
{
strSql = strSql + " Where a.lwtm Like '%" + s_jiansuoci + "%' ";
}
if (s_tujing.compareTo("zz")==0)
{
strSql=strSql + ",lwzz b,zzlwlj c Where a.lwbh=c.lwbh And c.zzbh=b.zzbh And b.zzxm Like '%"+s_jiansuoci+"%' ";
}
if (s_tujing.compareTo("bm")==0)
{
strSql=strSql + ",bm b,bmlwlj c Where a.lwbh=c.lwbh And c.bmbh=b.bmbh And b.zzbm Like '%"+s_jiansuoci+"%' ";
}
if (s_tujing.compareTo("xk")==0)
{
strSql=strSql + ",lwxk b,xklwlj c Where a.lwbh=c.lwbh And c.xkbh=b.xkbh And b.xk Like '%"+s_jiansuoci+"%' ";
}
if (s_tujing.compareTo("gjc")==0)
{
strSql=strSql + ",gjc b,gjclwlj c Where a.lwbh=c.lwbh And c.gjcbh=b.gjcbh And b.gjc Like '%"+s_jiansuoci+"%' ";
}
if(!s_year.equals("")&&
!s_nian.equals(""))
{
strSql=strSql + " And a.nian>="+s_year+" And a.nian<="+s_nian;
}
}
if(j==2)
{
strSql = "select count(*) as t from lwmx a";
if (s_tujing.compareTo("tm")==0)
{
strSql = strSql + " Where a.lwtm Like '%" + s_jiansuoci + "%' ";
}
if (s_tujing.compareTo("zz")==0)
{
strSql=strSql + ",lwzz b,zzlwlj c Where a.lwbh=c.lwbh And c.zzbh=b.zzbh And b.zzxm Like '%"+s_jiansuoci+"%' ";
}
if (s_tujing.compareTo("bm")==0)
{
strSql=strSql + ",bm b,bmlwlj c Where a.lwbh=c.lwbh And c.bmbh=b.bmbh And b.zzbm Like '%"+s_jiansuoci+"%' ";
}
if (s_tujing.compareTo("xk")==0)
{
strSql=strSql + ",lwxk b,xklwlj c Where a.lwbh=c.lwbh And c.xkbh=b.xkbh And b.xk Like '%"+s_jiansuoci+"%' ";
}
if (s_tujing.compareTo("gjc")==0)
{
strSql=strSql + ",gjc b,gjclwlj c Where a.lwbh=c.lwbh And c.gjcbh=b.gjcbh And b.gjc Like '%"+s_jiansuoci+"%' ";
}
if(!s_year.equals("")&&
!s_nian.equals(""))
{
strSql=strSql + " And a.nian>="+s_year+" And a.nian<="+s_nian;
}
}
return strSql;
}
catch(Exception e){
System.out.print("strSql");
}
return strSql;//返回字符串
}
public strsqlpd() {
}
}