You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
114 lines
3.7 KiB
114 lines
3.7 KiB
package com.demo;
|
|
|
|
import java.io.IOException;
|
|
import java.sql.Connection;
|
|
import java.sql.DriverManager;
|
|
import java.sql.PreparedStatement;
|
|
import java.sql.ResultSet;
|
|
import java.sql.SQLException;
|
|
import java.util.ArrayList;
|
|
|
|
import javax.servlet.ServletException;
|
|
import javax.servlet.annotation.WebServlet;
|
|
import javax.servlet.http.HttpServlet;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
import com.domain.Production;
|
|
|
|
/**
|
|
* Servlet implementation class TuserServlet
|
|
*/
|
|
@WebServlet(name = "queryproductionServlet", urlPatterns = { "/query-production" })
|
|
public class QueryProductionServlet extends HttpServlet {
|
|
private static final long serialVersionUID = 1L;
|
|
Connection dbconn=null;
|
|
public void init() {
|
|
String driver = "com.mysql.cj.jdbc.Driver";
|
|
String dburl = "jdbc:mysql://127.0.0.1:3306/tooth?useSSL=true";
|
|
String username = "root";
|
|
String password = "root";
|
|
try{
|
|
Class.forName(driver); // 加载驱动程序
|
|
// 创建连接对象
|
|
dbconn = DriverManager.getConnection(
|
|
dburl,username,password);
|
|
}catch(ClassNotFoundException e1){
|
|
System.out.println(e1);
|
|
getServletContext().log("驱动程序类找不到!");
|
|
}catch(SQLException e2){
|
|
System.out.println(e2);
|
|
}
|
|
}
|
|
|
|
|
|
public void doGet(HttpServletRequest request,
|
|
HttpServletResponse response)
|
|
throws ServletException,IOException{
|
|
|
|
|
|
ArrayList<Production> productionList = null;
|
|
productionList = new ArrayList<Production>();
|
|
try{
|
|
String sql="SELECT * FROM Production";
|
|
PreparedStatement pstmt = dbconn.prepareStatement(sql);
|
|
ResultSet rst = pstmt.executeQuery();
|
|
while(rst.next()){
|
|
Production s = new Production();
|
|
s.setPid(rst.getInt("pid"));
|
|
s.setPrice(rst.getString("price"));
|
|
s.setProm(rst.getString("prom"));
|
|
s.setClassify(rst.getString("classify"));
|
|
s.setStore(rst.getString("store"));
|
|
|
|
productionList.add(s);
|
|
}
|
|
if(!productionList.isEmpty()){
|
|
request.getSession().setAttribute("productionList",productionList);
|
|
response.sendRedirect("da-production.jsp");
|
|
}else{
|
|
response.sendRedirect("error.jsp");
|
|
}
|
|
}catch(SQLException e){
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
// public void doPost(HttpServletRequest request,
|
|
// HttpServletResponse response)
|
|
// throws ServletException,IOException{
|
|
// String id=request.getParameter("Doid");
|
|
// try{
|
|
// String sql="SELECT * FROM Schedule WHERE Doid = ?";
|
|
// PreparedStatement pstmt=dbconn.prepareStatement(sql);
|
|
// pstmt.setString(1,id);
|
|
// ResultSet rst=pstmt.executeQuery();
|
|
// if(rst.next()){
|
|
// Tuser tuser = new Tuser();
|
|
// tuser.setUid(rst.getString("Uid"));
|
|
// tuser.setUname(rst.getString("uname"));
|
|
// tuser.setUpassword(rst.getString("upassword"));
|
|
// tuser.setUsex(rst.getString("usex"));
|
|
// tuser.setUage(rst.getString("uage"));
|
|
// tuser.setUtel(rst.getString("utel"));
|
|
// tuser.setCid(rst.getString("cid"));
|
|
//
|
|
// request.getSession().setAttribute("tuser", tuser);
|
|
// response.sendRedirect("displaySchedule.jsp");
|
|
// }else{
|
|
// response.sendRedirect("error.jsp");
|
|
// }
|
|
// }catch(SQLException e){
|
|
// e.printStackTrace();
|
|
// }
|
|
// }
|
|
public void destory() {
|
|
try {
|
|
dbconn.close();
|
|
}catch(Exception e){
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
}
|
|
|
|
|