0
点赞
收藏
分享

微信扫一扫

jsp新代码第241课

码农K 2022-05-19 阅读 34


new241.jsp

package pack03;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

public class new241
{
public Connection getConnection() throws Exception
{
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/test?&useUnicode=true&characterEncoding=utf8";
String user = "root";
String pwd ="mysql123";
Connection conn = DriverManager.getConnection(url,user,pwd);
return conn;
}

public List<new240> finAll() throws Exception
{
Connection conn = getConnection();
String sql = "select id,title,content,author,createtime from aa_notes";
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql);
List<new240> noteList = new ArrayList<new240>();
while (rs.next())
{
new240 tn = new new240();
tn.setId(rs.getInt("id"));
tn.setTitle(rs.getString("title"));
tn.setContent(rs.getString("content"));
tn.setAuthor(rs.getString("author"));
tn.setCreateTime(rs.getTimestamp("createtime"));
noteList.add(tn);
}
conn.close();
return noteList;
}
}


举报

相关推荐

0 条评论