import java.io.IOException;
import java.io.PrintWriter;
import java.sql.*;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/PetDatabase")
public class PetDatabase extends HttpServlet {
// JDBC �����������ݿ� URL
static final String JDBC_DRIVER = "com.mysql.cj.jdbc.Driver";
static final String DB_URL = "jdbc:mysql://localhost:3306/petstore?&useSSL=false&serverTimezone=UTC";
// ���ݿ���û��������룬��Ҫ�����Լ�������
static final String USER = "root";
static final String PASS = "lxy790524";
String sqlStr = "select pet_ID,pet_Name,Age,Sex,visit_time,visit_attention from medical_record";
// String sqlInsert = "insert into medical_record " +"VALUES (23, 'Mike', '3','男','2022-09-12','发热')";
String sqlInsert = "";
//String sqlUpdate = "update medical_record " +"set visit_time = '2022-10-10' where pet_ID in (1,3)";
String sqlUpdate="";
/**
* @see HttpServlet#HttpServlet()
*/
public PetDatabase() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Connection conn = null;
Statement stmt = null;
// ������Ӧ��������
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
String title = "Servlet MySQL Connection";
String docType = "<!DOCTYPE html>\n";
out.println(docType +
"<html>\n" +
"<head><title>" + title + "</title></head>\n" +
"<body bgcolor=\"#f0f0f0\">\n" +
"<h1 align=\"center\">" + title + "</h1>\n");
try{
Class.forName("com.mysql.cj.jdbc.Driver");
System.out.println( "���������ɹ�!" );
Connection con = DriverManager.getConnection(DB_URL, USER,PASS );
System.out.println( "�������ݿ�ɹ�!" );
Statement st = con.createStatement();
System.out.println( "����Statement�ɹ�!" );
System.out.println( "��ʼ��ѯ����" );
//�������
//st.executeUpdate(sqlInsert);
//System.out.println("��������ݳɹ�");
String m_time=request.getParameter("m_time");
System.out.println(m_time);
sqlUpdate="update medical_record "+"set visit_time = "+m_time+" where pet_ID in (1,3)";
//��������
st.executeUpdate(sqlUpdate);
System.out.println("�������ݳɹ�");
String pet_name=request.getParameter("pname");
String pet_id=request.getParameter("id");
String pet_age=request.getParameter("age");
String pet_sex=request.getParameter("sex");
String pet_attention=request.getParameter("attention");
System.out.println(pet_name);
sqlInsert = "insert into medical_record VALUES " +
"("+"'"+pet_id+"'"+","+"'"+pet_name+"'"+","+"'"+pet_age+"'"+","+"'"+pet_sex+"'"+","+"'"+m_time+"'"+","+"'"+pet_attention+"'"+")";
st.executeUpdate(sqlInsert);
System.out.println("�������ݳɹ�");
//��ѯ����
ResultSet rs = st.executeQuery( sqlStr );
System.out.println( "��ѯ���ݲ����ɹ�!" );
System.out.println( "----------------!" );
while(rs.next()){
// ͨ���ֶμ���
int id = rs.getInt("pet_ID");
String name = rs.getString("pet_Name");
int age = rs.getInt("Age");
String sex = rs.getString("Sex");
String time = rs.getString("visit_time");
String attention = rs.getString("visit_attention");
// �������
out.println("pet_ID: " + id);
out.println(", name: " + name);
out.println(", age: " + age);
out.println(", sex: " + sex);
out.println(", visit_time: " +time );
out.println(", visit_attention: " + attention);
out.println("<br />");
}
out.println("</body></html>");
// ��ɺ�ر�
} catch(SQLException se) {
// ���� JDBC ����
se.printStackTrace();
} catch(Exception e) {
// ���� Class.forName ����
e.printStackTrace();
}finally{
// ��������ڹر���Դ�Ŀ�
try{
if(stmt!=null)
stmt.close();
}catch(SQLException se2){
}
try{
if(conn!=null)
conn.close();
}catch(SQLException se){
se.printStackTrace();
}
}
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
基于HTML+java的宠物就诊信息管理系统源码(期末课程设计).zip 【备注】 主要针对计算机相关专业的正在做毕设的学生和需要项目实战的Java、HTML学习者。 也可作为课程设计、期末大作业。包含:项目源码、项目说明等,该项目可以直接作为毕设使用。 也可以用来学习参考借鉴!
资源推荐
资源详情
资源评论
收起资源包目录
基于HTML+java的宠物就诊信息管理系统源码(期末课程设计).zip (85个子文件)
项目说明.md 25B
pom.xml 2KB
src
main
java
ajax.java 4KB
DatabaseAccess.java 4KB
ForwardServlet.java 2KB
CheckBox.java 2KB
LifeCycleServlet.java 4KB
FirstServlet.java 515B
PetDatabase.java 6KB
pettest.java 5KB
ReadParams.java 3KB
HelloForm.java 2KB
Person.java 569B
PostServlet.java 5KB
webapp
WEB-INF
web.xml 637B
index.jsp 52B
checkbox.html 404B
read.html 410B
useBean.html 1KB
ajax.html 3KB
PetDatabase.html 630B
postPersonalInformation.html 4KB
hello.html 303B
test.html 2KB
.idea
workspace.xml 18KB
misc.xml 638B
compiler.xml 537B
encodings.xml 768B
target
classes
Person.class 868B
LifeCycleServlet.class 5KB
ForwardServlet.class 2KB
ajax.class 4KB
FirstServlet.class 859B
HelloForm.class 2KB
ReadParams.class 3KB
DatabaseAccess.class 5KB
pettest.class 5KB
PetDatabase.class 5KB
PostServlet.class 5KB
CheckBox.class 2KB
main
webapp
WEB-INF
web.xml 637B
index.jsp 52B
checkbox.html 404B
read.html 410B
useBean.html 1KB
ajax.html 3KB
PetDatabase.html 630B
postPersonalInformation.html 4KB
hello.html 303B
test.html 2KB
ServletMavenTest
WEB-INF
classes
Person.class 868B
LifeCycleServlet.class 5KB
ForwardServlet.class 2KB
ajax.class 4KB
FirstServlet.class 859B
HelloForm.class 2KB
ReadParams.class 3KB
DatabaseAccess.class 5KB
pettest.class 5KB
PetDatabase.class 5KB
PostServlet.class 5KB
CheckBox.class 2KB
main
webapp
WEB-INF
web.xml 637B
index.jsp 52B
checkbox.html 404B
read.html 410B
useBean.html 1KB
ajax.html 3KB
PetDatabase.html 630B
postPersonalInformation.html 4KB
hello.html 303B
test.html 2KB
lib
javax.servlet-api-4.0.1.jar 93KB
web.xml 637B
index.jsp 52B
checkbox.html 404B
read.html 410B
useBean.html 1KB
ajax.html 3KB
PetDatabase.html 630B
postPersonalInformation.html 4KB
hello.html 303B
test.html 2KB
META-INF
MANIFEST.MF 87B
ServletMavenTest.iml 80B
共 85 条
- 1
资源评论
Make程序设计
- 粉丝: 6566
- 资源: 3571
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功