📄 articlecommand.java
字号:
package nepalon.simplestruts;
/** *//**
* <p>Title: MVC framework</p>
* <p>Description: 文章业务类<p>
* <p>Copyright: R2003</p>
* @author Nepalon
* @version 1.0
*/
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.lang.*;
import java.sql.*;
import javax.sql.*;
import nepalon.simplestruts.CommentItem;
public class ArticleCommand
{
public ArticleCommand() {}
public String getAllArticle(HttpServletRequest request, HttpServletResponse response)
throws javax.servlet.ServletException, java.io.IOException
{
Connection conn=null;
String con_user = "root";
String con_password = "123";
String con_dburl = "jdbc:mysql://localhost:3306/mysql";
String con_driver = "com.mysql.jdbc.Driver";
PreparedStatement pstmt=null;
ResultSet rsComment=null;
// Vector vectorComment = new Vector();
//这是因为java se 5.0新增加了对泛型的支持,在使用vector的时候要求你指明存储内容的类型
//java.util.Vector<String> vectorComment = new java.util.Vector<String>();
Vector<Object> vectorComment = new Vector<Object>();
//Vector<String> vectorTT = new Vector<String>();
String selectSQL= "SELECT content, time FROM article ";
try
{
Class.forName(con_driver);
conn = DriverManager.getConnection(con_dburl,con_user,con_password);
pstmt=conn.prepareStatement(selectSQL);
rsComment=pstmt.executeQuery();
while(rsComment.next())
{
CommentItem commentItem = new CommentItem(); //此句不能放在while语句之前
commentItem.setContent(rsComment.getString(1));
commentItem.setTime(rsComment.getDate(2));
vectorComment.add(commentItem);
}
vectorComment.trimToSize();
}
catch (Exception e){}//做相应的处理
//代码(1)保存处理结果并返回跳转页面
request.setAttribute("vectorComment", vectorComment);
return "/showallarticle.jsp";
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -