publicclassUserControllerextendsBaseControl{privatestaticfinalLoggerlogger=LoggerFactory.getLogger(UserController.class);privateUserServiceuserService;privatefinalstaticS...
public class UserController extends BaseControl {
private static final Logger logger=LoggerFactory.getLogger(UserController.class);
private UserService userService;
private final static String URL = "jdbc:sqlserver://localhost:1433;DatabaseName=RUNOOB";
private static final String USER="sa";
private static final String PASSWORD="1234561";
public void setUserService(UserService userService) {
this.userService = userService;
}
public ModelAndView NewFile(HttpServletRequest request,HttpServletResponse response) {
logger.debug("NewFile(HttpServletRequest request,HttpServletResponse response) ");
//父表下拉菜单
return new ModelAndView("app/train/user/NewFile");
}
public ModelAndView getdata(HttpServletRequest request,HttpServletResponse response) throws SQLException {
logger.debug("NewFile(HttpServletRequest request,HttpServletResponse response) ");
Connection conn=null;
try {
//1.加载驱动程序
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
//2.获得数据库的连接
conn=(Connection)DriverManager.getConnection(URL,USER,PASSWORD);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
Statement stmt = conn.createStatement();
。
ResultSet rs = stmt.executeQuery("select id,name,url,alexa,country from Websites");
String s = "";
while(rs.next()){//如果对象中有数据,就会循环打印出来
System.out.println(rs.getInt("id")+","+rs.getString("name")+","+rs.getString("url")+","+rs.getString("alexa")+","+rs.getString("country"));
s += rs.getString("name") + ",";
}
super.outJson(s,response);
return null;
}
我现在这样弄的,只能输出一行"name",我现在想将这5行数据都输出,怎么弄?
展开