程序中关于返回值的问题(100分)

  • 主题发起人 主题发起人 unixhost
  • 开始时间 开始时间
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("")&amp;&amp;
!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("")&amp;&amp;
!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() {
}

}
 
public int strSql(String getTj[],int j){
应该是:
public String strSql()
另外如何返回数组。
 
返回数组和字符串是一样的,直接写就可以了
# public static String[] split(String source, String delim) {
# String[] wordLists;
# if (source == null) {
# wordLists = new String[1];
# wordLists[0] = source;
# return wordLists;
# }
 
int i;
for(i=0;i<5;i++)
return getTj;//返回这个值。
改成
return getTJ;
 
此段程序这样做是达不到目的的。不过也谢谢大家参与。
 
String aa[] =new String[5];
for(i=0;i<5;i++){
aa= getTj;//返回这个值。
}
return aa;
 

Similar threads

后退
顶部