<Myeclipse> Servlet之连接数据库查询
来源:互联网 发布:p2p网络管理器 编辑:程序博客网 时间:2024/05/16 07:12
package servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import att.Att;
public class Select_t extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
request.setCharacterEncoding("utf-8");
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/a","root","0519");
String chack_sql = "select * from t_user";
ps = con.prepareStatement(chack_sql);
rs = ps.executeQuery();
List<Att> list = new ArrayList();
while(rs.next())
{
int id = rs.getInt("id");
String username = rs.getString("username");
String password = rs.getString("password");
Att a = new Att(id,username,password);
list.add(a);
}
request.setAttribute("list", list);
request.getRequestDispatcher("Show_t.jsp").forward(request, response);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request,response);
}
}
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import att.Att;
public class Select_t extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
request.setCharacterEncoding("utf-8");
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/a","root","0519");
String chack_sql = "select * from t_user";
ps = con.prepareStatement(chack_sql);
rs = ps.executeQuery();
List<Att> list = new ArrayList();
while(rs.next())
{
int id = rs.getInt("id");
String username = rs.getString("username");
String password = rs.getString("password");
Att a = new Att(id,username,password);
list.add(a);
}
request.setAttribute("list", list);
request.getRequestDispatcher("Show_t.jsp").forward(request, response);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request,response);
}
}
阅读全文
0 0
- <Myeclipse> Servlet之连接数据库查询
- orcale数据库之连接查询
- 数据库查询之(Ⅲ)连接查询
- 数据库之联合查询和连接查询
- MyEclipse之无法连接到MySQL数据库
- Servlet学习之四连接数据库
- java servlet jdbc 连接sqlserver数据库查询和修改
- Oracle数据库之SQL连接查询
- 数据库之查询的连接方式
- Unity之基础查询,连接数据库
- 数据库SQL之表关系&连接查询
- SQL----关系型数据库之连接查询
- myeclipse 连接数据库故障
- myeclipse中连接数据库
- myeclipse 连接数据库
- MyEclipse连接数据库MySQL
- Myeclipse连接MySQL数据库
- MyEclipse 连接MySQL数据库
- 51单片机矩阵键盘C程序
- Intellij IDEA新建SpringMVC配置
- Oi
- 概率基础及贝叶斯决策理论
- 计算几何(具象的难题)
- <Myeclipse> Servlet之连接数据库查询
- 操作系统之内存管理(一)(未引入虚拟内存之前部分)
- Rust : 求出一个字符串数组中最长的公共连续子序列
- 10.15总结
- 2016级算法第一次上机——E ModricWang's QuickSort
- 猜数字游戏
- centos7 配置多个Tomcat
- Drawerlayout
- 实现侧栏,为Xlistview获取网络数据