导入以下包
commons-beanutils-1.8.0.jar,commons-lang-2.4.jar,ezmorph-1.0.6.jar,json-lib-2.2.3-jdk15.jar,commons-collections-3.2.1.jar
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
ArrayList<EmpBean> empArray = new ArrayList<EmpBean>();
empArray = test();
out.println(JSONArray.fromObject(empArray));
}
public static ArrayList<EmpBean> test()
{
ArrayList<EmpBean> empArray = new ArrayList<EmpBean>();
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
con = DriverManager.getConnection(" jdbc:oracle:thin:@127.0.0.1:1521:myora",
"scott",
"scott");
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("select * from emp");
System.out.println(rs.TYPE_SCROLL_INSENSITIVE);
while (rs.next())
{
System.out.println(rs.getRow());
EmpBean bean = new EmpBean();
bean.setEmpNo(rs.getString("empno"));
bean.setEname(rs.getString("ename"));
bean.setJob(rs.getString("job"));
bean.setMgr(rs.getString("mgr"));
bean.setHireadte(rs.getString("HIREDATE"));
bean.setSal(rs.getString("sal"));
bean.setComm(rs.getString("comm"));
bean.setDeptNo(rs.getString("deptNo"));
empArray.add(bean);
}
}
catch (Exception e)
{
e.printStackTrace();
}
return empArray;
}