我想把数据库中的东西取出来放到Vector中,然后再从Vector中取出来打印,下面是我写的,但是没有输出结果,请各位高手指点迷津
import javax.servlet.*;
import java.io.*;
import javax.servlet.http.*;
import java.util.*;
public class Dao extends HttpServlet
{
public void doGet(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException
{
response.setContentType("text/html;charset=gb2312");
PrintWriter out=response.getWriter();
out.println("<html><body>gfjkdogjfdigohf<br>");
Vector v = new Vector();
try
{
Luo d = new Luo();
v = d.Da();
if (v != null)
{
if (v.size() > 0)
{
for(int i = 0;i < v.size();i++)
{
out.println(((Dat)v.elementAt(i)).get_sno() + "\t" + ((Dat)v.elementAt(i)).get_name()
+ "\t" + ((Dat)v.elementAt(i)).get_sex() + "<br>");
}
}
}
}
catch(Exception e)
{
e.printStackTrace();
}
out.println(v.size());
out.println("<br>cxvcxzvcxz</body></html>");
}
public void doPost(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException
{
doGet(request,response);
}
}
import java.sql.*;
import javax.servlet.*;
import java.io.*;
import java.util.*;
public class Dat
{
String sno = "";
String name = "";
String sex = "";
String age = "";
String department = "";
public void set_sno(String sno)
{
this.sno = sno;
}
public String get_sno()
{
return this.sno;
}
public void set_name(String name)
{
this.name=name;
}
public String get_name()
{
return this.name;
}
public void set_sex(String sex)
{
this.sex = sex;
}
public String get_sex()
{
return this.sex;
}
public void set_age(String age)
{
this.age = age;
}
public String get_()
{
return this.age;
}
public void set_department(String department)
{
this.department = department;
}
public String get_department()
{
return this.department;
}
}
import java.sql.*;
import javax.servlet.*;
import java.io.*;
import java.util.*;
public class Luo
{
public Vector Da() throws Exception
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection("jdbc:odbc:wanglei","sa","");
Statement stat = conn.createStatement();
ResultSet result = stat.executeQuery("select * from students");
Vector v = new Vector();
Dat da = null;
while(result.next())
{
da = new Dat();
da.set_sno(result.getString("sno"));
da.set_name(result.getString("name"));
da.set_sex(result.getString("sex"));
da.set_age(result.getString("age"));
da.set_department(result.getString("department"));
v.addElement(da);
}
return v;
}
}