一道难题被自己亲手解决,真的是比洞房花烛夜还兴奋.
请允许我把代码贴上来.
//jspfindall.jsp
<%@ page contentType="text/html; charset=GBK" import="java.sql.*,java.util.*,jspfind.SqlVectorAll" %>
<html>
<head>
<title>
jspfindall
</title>
</head>
<body bgcolor="#ffffff">
<form action="" method="POST">
年龄:<input type="text" name="age" />
<input type="submit" value="查询" />
<table width="300" border="1">
<%
if(request.getParameter("age")==null){
return;
}
int age=Integer.parseInt(request.getParameter("age"));
SqlVectorAll sva=new SqlVectorAll();
Vector v=sva.getchaxun(age);
for(int i=0;i<v.size();i++){
%>
<tr>
<%
for(int j=0;j<((Vector)v.get(i)).size();j++){
%>
<td><%=((Vector)v.get(i)).get(j).toString()%></td>
<%}%>
</tr>
<%}%>
</table>
</form>
</body>
</html>
//
//SqlVectorAll.java
package jspfind;
import java.sql.*;
import java.util.*;
public class SqlVectorAll {
public SqlVectorAll() {
}
Connection con=null;
private Connection getcon(){
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection(
"jdbc:odbc:driver=sql server;server=(local);database=test");
} catch (SQLException ex) {
System.out.println(ex);
} catch (ClassNotFoundException ex) {
}
return con;
}
public Vector getchaxun(int age){
Connection con=getcon();
Vector data = new Vector();
if(con==null){
return data;
}
Statement st=null;
String sql="select * from test where age >"+age;
try {
st = con.createStatement();
ResultSet rs=st.executeQuery(sql);
int cols=rs.getMetaData().getColumnCount();//获取列数
while(rs.next()){
Vector t= new Vector();
for(int i=1;i<=cols;i++){
t.add(rs.getString(i));
}
data.add(t);
}
} catch (SQLException ex) {
}
return data;
}
}
可能对大虾们这题算不了什么,但对于我这个JAVA残缺的人来说,真的是无与伦比.