jsp部分:
<%
String text=request.getParameter("textfield");
String radio=request.getParameter("radiobutton");
String backdata[];
backdata=queryedId.getRs(radio,text);
out.print("<Table Border>");
out.print("<TR>");
out.print("<TH width=100>"+"索引");
out.print("<TH width=100>"+"书名");
out.print("<TH width=100>"+"作者");
out.print("<TH width=100>"+"年份");
out.print("<TH width=100>"+"价格");
out.print("</TR>");
out.print("<TR>");
out.print("<TD >"+backdata[0]+"</TD>");
out.print("<TD >"+backdata[1]+"</TD>");
out.print("<TD >"+backdata[2]+"</TD>");
out.print("<TD >"+backdata[3]+"</TD>");
out.print("<TD >"+backdata[4]+"</TD>");
out.print("</TR>") ;
out.print("</Table>");
%>
javaBean
package book;
import java.sql.*;
public class queryed {
String choose="",textent="" ;
String[] result=new String[5];
public queryed(){
}
public void setChoose(String radiobutton){
choose=radiobutton;
}
public String getChoose(){
return choose;
}
public void setTextent(String textfield){
textent=textfield;
}
public String getTextent(){
return textent;
}
public String[] getRs(String radio2,String text2){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}catch(ClassNotFoundException e){}
try{
Connection con;
Statement sql;
ResultSet rs;
con=DriverManager.getConnection("jdbc:odbc:yfzyzr","sa","");
sql=con.createStatement();
String condition="";
condition="SELECT * FROM book WHERE "+radio2+" LIKE '%"+text2+"%' ORDER BY bookid";
rs=sql.executeQuery(condition);
result[0]=rs.getString("bookId");
result[1]=rs.getString("bookname");
result[2]=rs.getString("author");
result[3]=rs.getString("year");
result[4]=rs.getString("price");
con.close();
}catch(SQLException e){}
return result;
}
}
但结果好象并没有取得,查询结果!
也就是查询结果的数组元素并不能被输出.
[此贴子已经被作者于2007-1-1 14:06:46编辑过]