主题:怎么查不到数据,帮我看下!
javabean 如下:conn.java
package test;
import java.sql.*;
public class conn {
String keyword;
public conn() {
keyword="";
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
catch(ClassNotFoundException e)
{}
}
public void setkeyword(String s){
keyword=s;
try{byte b[]=keyword.getBytes("ISO-8859-1");
keyword=new String("b");
}
catch(Exception e){}
}
public StringBuffer ikeyword(){
Connection con=null;
Statement sql=null;
ResultSet rs=null;
StringBuffer buffer=new StringBuffer();
try
{con=DriverManager.getConnection("jdbc:odbc:db");
sql=con.createStatement();
String condition="SELECT * FROM students where number="+" '"+keyword+"'";
rs=sql.executeQuery(condition);
buffer.append("<table>");
buffer.append("<tr>");
buffer.append("<th width=100>"+"学号");
buffer.append("<th width=100>"+"姓名");
buffer.append("<th width=100>"+"数学成绩");
buffer.append("<th width=100>"+"英语成绩");
buffer.append("<th width=100>"+"物理成绩");
buffer.append("</tr>");
while(rs.next())
{buffer.append("<tr>");
buffer.append("<td>"+rs.getString("number")+"</td>");
buffer.append("<td>"+rs.getString("name")+"</td>");
buffer.append("<td>"+rs.getInt("math")+"</td>");
buffer.append("<td>"+rs.getInt("english")+"</td>");
buffer.append("<td>"+rs.getInt("physics")+"</td>");
buffer.append("</tr>");
}
buffer.append("</table>");
con.close();
return buffer;
}
catch(Exception ex)
{return new StringBuffer("无法建立查询");}
}
}
页面如下:keyword.jsp
<%@page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage=""%>
<%@page import="test.conn"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<body>
<form name="form1" method="post" action="keyword.jsp">
<p>成绩查询</p>
<p> 输入学号:
<input type="text" name="keyword">
<input type="submit" name="Submit" value="提交">
</p>
</form>
<jsp:useBean id="database" class="test.conn" scope="request"></jsp:useBean>
<jsp:setProperty name="database" property="keyword" param="keyword" />
<p> 查询到的记录:
<br>
<%StringBuffer b = database.ikeyword();%>
<%=b%>
</body>
</html>
</body></html>
问题:数据裤里边有学号为001的学生信息,可是查询的时候没有显示出来!
package test;
import java.sql.*;
public class conn {
String keyword;
public conn() {
keyword="";
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
catch(ClassNotFoundException e)
{}
}
public void setkeyword(String s){
keyword=s;
try{byte b[]=keyword.getBytes("ISO-8859-1");
keyword=new String("b");
}
catch(Exception e){}
}
public StringBuffer ikeyword(){
Connection con=null;
Statement sql=null;
ResultSet rs=null;
StringBuffer buffer=new StringBuffer();
try
{con=DriverManager.getConnection("jdbc:odbc:db");
sql=con.createStatement();
String condition="SELECT * FROM students where number="+" '"+keyword+"'";
rs=sql.executeQuery(condition);
buffer.append("<table>");
buffer.append("<tr>");
buffer.append("<th width=100>"+"学号");
buffer.append("<th width=100>"+"姓名");
buffer.append("<th width=100>"+"数学成绩");
buffer.append("<th width=100>"+"英语成绩");
buffer.append("<th width=100>"+"物理成绩");
buffer.append("</tr>");
while(rs.next())
{buffer.append("<tr>");
buffer.append("<td>"+rs.getString("number")+"</td>");
buffer.append("<td>"+rs.getString("name")+"</td>");
buffer.append("<td>"+rs.getInt("math")+"</td>");
buffer.append("<td>"+rs.getInt("english")+"</td>");
buffer.append("<td>"+rs.getInt("physics")+"</td>");
buffer.append("</tr>");
}
buffer.append("</table>");
con.close();
return buffer;
}
catch(Exception ex)
{return new StringBuffer("无法建立查询");}
}
}
页面如下:keyword.jsp
<%@page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage=""%>
<%@page import="test.conn"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<body>
<form name="form1" method="post" action="keyword.jsp">
<p>成绩查询</p>
<p> 输入学号:
<input type="text" name="keyword">
<input type="submit" name="Submit" value="提交">
</p>
</form>
<jsp:useBean id="database" class="test.conn" scope="request"></jsp:useBean>
<jsp:setProperty name="database" property="keyword" param="keyword" />
<p> 查询到的记录:
<br>
<%StringBuffer b = database.ikeyword();%>
<%=b%>
</body>
</html>
</body></html>
问题:数据裤里边有学号为001的学生信息,可是查询的时候没有显示出来!