0322-数据库与前后端的连接、数据库表的增删改查

前端 

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script src='js/jquery-3.7.1.min.js'></script>
<script>
//jquary+ajax发起请求
//传参形式不同 post用data{}传参
//get 只要能写地址的地方都可以发起get请求-->查询
//post ajax+jquery或form表单发起请求-------->修改 删除 添加
$.ajax({url:"demo?account=admin&password=123456",//请求路径type:"get",//请求方式 get post/*data:{account:"adminxsdf",password:"123456"},//参数域*/success:function(value){console.log(value);console.log(value.alexa)},//请求成功的回调函数error:function(){alert("出错啦")},//请求失败的回调函数})</script>
</head>
<body>hello
</body>
</html>

后端 

package com.qc.servlet;import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;/*** Servlet implementation class lkj*/
@WebServlet("/demo")
public class lkj extends HttpServlet {private static final long serialVersionUID = 1L;/*** @see HttpServlet#HttpServlet()*/public lkj() {super();// TODO Auto-generated constructor stub}/*** @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)*///getprotected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {System.out.println("get执行啦!");//接收参数String acc=request.getParameter("account");String pass=request.getParameter("password");String res="登录失败";if(acc.equals("admin")&&pass.equals("123456")) {res="{ \"name\":\"runoob\",\"alexa\":1000 }";}//设置编码request.setCharacterEncoding("utf-8");response.setCharacterEncoding("utf-8");//设置返回的数据为JSON格式response.setContentType("text/json;charset=utf-8");//给前端响应数据(相当于return)response.getWriter().write(res);}/*** @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)*/protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {System.out.println("post执行啦");}}

Navicat Premium

-- 查找(不区分大小写)
select name,age,sex,id from student 
select *from student-- 条件查询 where子语句
-- 运算符
-- =等于
-- >大于
-- >=大于等于
-- <小于
-- <=小于等于
-- != <> 不等于
select *from student where sex="男"
select *from student where age=20
-- between ..and   []select *from student where age between 20 and 25
-- and 与
-- or 或
-- not 非 主要用在is inselect *from student where age>20 and age<25
select *from student where age<20 or age<25select *from student where age=20 or age=25 or age=23-- in 包含
select *from student where age in(20,25,23)
select *from student where id not in(1,5,3)-- is null 判空
select *from student where age is not null-- 模糊查找 like _代表一个字符 %代表任意个字符
select *from student where name like "张_"
select *from student where name like "%张%"-- 分页查询 limit
-- limit a,b a表示起始索引值(0开始) b表示查询的个数
-- limit b offset a
select *from student limit 0,5
select *from student limit 5,5
select *from student limit 10,5-- 一页大小 pageSize  当前页码 page
select *from student limit (page-1)*pageSize,pageSizeselect *from student where name like "%张%" limit 0,3-- 排序子语句
-- order by 列名 desc 降序| asc 升序(默认)
select *from student order by age desc-- where 排序 限制
select * from student where sex="女" order by age desc limit 0,3-- 聚合函数 分组函数
-- min() 最小
-- max() 最大
-- sum() 求和
-- avg() 求平均
-- count() 求数量 count(字段名称)不统计值为null的字段
select sum(age) from student
-- 后续修改条件用having ;group by分组
select avg(age),class from student where sex="女" group by class having class=1-- 添加
insert into student(name,age,sex) values("王祖贤",26,"女")insert into student(name,age,sex) values("王祖",26,"女")
-- 修改
update student set name="韩孝周",age=24,sex="女" where id=5-- 删除
delete from student where id=2
delete from student where id in (3,6,7)-- 多表查询
-- 重命名 as 新名字 as可省
select * from student,class.c_name where student.c_id=class.id 
select s1.*,class.c_name as 班级名称 from student as s1,class where s1.c_id=class.id
select 学生表.*,cname,score from 学生表,课程表,选课表 where 学生表.id=选课表.s_id and 课程表.id=选课表.c_id-- 连表查询
-- 内连接 join... on
-- 外连接
--   左外连接 left join...on
--   右外连接 right join...on
select *from student right join class on student.c_id=class.idselect 学生表.*,cname,score from 学生表 join 课程表 join 选课表 on 学生表.id=选课表.s_id and 课程表.id=选课表.c_id
select 学生表.*,cname,score from 学生表 join 选课表 on 学生表.id=选课表.s_id join 课程表 on 课程表.id=选课表.c_id


 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/41487.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

matlab打开两个工程

1、问题描述 写代码时&#xff0c;需要实时参考别人的代码&#xff0c;需要同时打开2个模型&#xff0c;当模型在同一个工程内时&#xff0c;这是可以直接打开的&#xff0c;如图所示 2、解决方案 再打开一个MATLAB主窗口 这个时候就可以同时打开多个模型了 3、正确的打开方…

深度剖析HTTP协议—GET/PUT请求方法的使用-构造请求的方法

活动发起人小虚竹 想对你说&#xff1a; 这是一个以写作博客为目的的创作活动&#xff0c;旨在鼓励大学生博主们挖掘自己的创作潜能&#xff0c;展现自己的写作才华。如果你是一位热爱写作的、想要展现自己创作才华的小伙伴&#xff0c;那么&#xff0c;快来参加吧&#xff01…

SQL中体会多对多

我们可以根据学生与课程多对多关系的数据库模型&#xff0c;给出实际的表数据以及对应的查询结果示例&#xff0c;会用到JOINLEFT JOIN两种连接 1. 学生表&#xff08;students&#xff09; student_idstudent_name1张三2李四3王五 2. 课程表&#xff08;courses&#xff09…

【android】补充

3.3 常用布局 本节介绍常见的几种布局用法&#xff0c;包括在某个方向上顺序排列的线性布局&#xff0c;参照其他视图的位置相对排列的相对布局&#xff0c;像表格那样分行分列显示的网格布局&#xff0c;以及支持通过滑动操作拉出更多内容的滚动视图。 3.3.1 线性布局Linea…

uv:Rust 驱动的 Python 包管理新时代

在 Python 包管理工具层出不穷的今天&#xff0c;pip、pip-tools、poetry、conda 等各有千秋。而今天要介绍的 uv&#xff0c;则是一款由 Astral 团队推出、采用 Rust 编写的全新工具&#xff0c;目标直指成为 “Python 的 Cargo”。它不仅在性能上表现优异&#xff0c;而且在功…

package.json版本前缀

前言 执行 npm i 下载依赖后&#xff0c;element-plus出现bug&#xff08;单页面多个date-picker同时开启&#xff09;&#xff0c;这是 v2.9.0 的问题&#xff0c;但是项目 package.json 中版本如下&#xff1a; "element-plus": "^2.7.6",乍一看并不是…

CSS+JS 堆叠图片动态交互切换

结合DeepSeek提供的代码&#xff0c;终于实现了堆叠两张图片动态循环切换&#xff0c;以下是代码&#xff1a; 通过绝对定位放了两张图片 <div class"col-lg-5" style"z-index: 40; position: relative;"><img src"images/banner_1.png&quo…

SpringCould微服务架构之Docker(2)

Docker和虚拟机的差别&#xff1a; 虚拟机是在操作系统中模拟硬件设备&#xff0c;然后运行另外一个操作系统。

好用的Markdown阅读编辑器Typora破解记录

Typora破解 一、下载Typora二、安装Typora三、破解Typora &#x1f600; 记录一下Typora破解记录&#xff0c;怕不常用忘记咯&#xff0c;感觉自己现在的脑子就像我的肠子一样&#xff0c;刚装进去就么得了。。。&#x1f614; Typroa算是用起来很舒服的Markdown阅读器了吧&am…

UI前端与数字孪生:打造智慧城市的双引擎

hello宝子们...我们是艾斯视觉擅长ui设计和前端数字孪生、大数据、三维建模、三维动画10年经验!希望我的分享能帮助到您!如需帮助可以评论关注私信我们一起探讨!致敬感谢感恩! 随着信息技术的飞速发展&#xff0c;智慧城市的概念逐渐从理论走向实践。智慧城市旨在通过运用物联网…

“征服HTML引号恶魔:“完全解析手册”!!!(quot;表示双引号)

&#x1f6a8;&#x1f4e2; "征服HTML引号恶魔&#xff1a;“完全解析手册” &#x1f4e2;&#x1f6a8; &#x1f3af; 博客引言&#xff1a;当引号变成"恶魔" &#x1f631; 是否遇到过这种情况&#xff1a; 写HTML时满心欢喜输入<div title"他…

k8s高可用集群安装

一、安装负载均衡器 k8s负载均衡器 官方指南 1、准备三台机器 节点名称IPmaster-1192.168.1.11master-2192.168.1.12master-3192.168.1.13 2、在这三台机器分别安装haproxy和keepalived作为负载均衡器 # 安装haproxy sudo dnf install haproxy -y# 安装Keepalived sudo yum …

node.js笔记

1. Node.js基本概念 1.1 什么是Node.js Node.js是一个开源、跨平台的JavaScript运行环境&#xff0c;广泛应用于各类项目。它基于Google Chrome的V8 JavaScript引擎&#xff0c;性能卓越。 Node.js在单个进程中运行&#xff0c;利用异步I/O操作避免阻塞&#xff0c;能高效处…

关于在vscode中的Linux 0.11 应用程序项目的生成和运行

首先我们需要需要查看镜像文件 查看软盘镜像文件 floppyb.img 中的内容 在 VSCode 的“Terminal”菜单中选择“Run Build Task...”&#xff0c;会在 VSCode 的顶部中间位置弹出一个 可以执行的 Task 列表&#xff0c;选择其中的“打开 floppyb.img”后会使用 Floppy Editor …

【JavaScript 简明入门教程】为了Screeps服务的纯JS入门教程

0 前言 0-1 Screeps: World 众所不周知&#xff0c;​Screeps: World是一款面向编程爱好者的开源大型多人在线即时战略&#xff08;MMORTS&#xff09;沙盒游戏&#xff0c;其核心机制是通过编写JavaScript代码来控制游戏中的单位&#xff08;称为“Creep”&#xff09;&#…

【CSS文字渐变动画】

CSS文字渐变动画 HTML代码CSS代码效果图 HTML代码 <div class"title"><h1>今天是春分</h1><p>正是春天到来的日子&#xff0c;花都开了&#xff0c;小鸟也飞回来了&#xff0c;大山也绿了起来&#xff0c;空气也有点嫩嫩的气息了</p>…

【论文阅读】基于思维链提示的大语言模型软件漏洞发现与修复方法研究

这篇文章来自于 Chain-of-Thought Prompting of Large Language Models for Discovering and Fixing Software Vulnerabilities 摘要 软件安全漏洞在现代系统中呈现泛在化趋势&#xff0c;其引发的社会影响日益显著。尽管已有多种防御技术被提出&#xff0c;基于深度学习&…

SpringMVC_day02

一、SSM 整合 核心步骤 依赖管理 包含 SpringMVC、Spring JDBC、MyBatis、Druid 数据源、Jackson 等依赖。注意点&#xff1a;确保版本兼容性&#xff08;如 Spring 5.x 与 MyBatis 3.5.x&#xff09;。 配置类 SpringConfig&#xff1a;扫描 Service 层、启用事务管理、导入…

基于ADMM无穷范数检测算法的MIMO通信系统信号检测MATLAB仿真,对比ML,MMSE,ZF以及LAMA

目录 1.算法运行效果图预览 2.算法运行软件版本 3.部分核心程序 4.算法理论概述 4.1 ADMM算法 4.2 最大似然ML检测算法 4.3 最小均方误差&#xff08;MMSE&#xff09;检测算法 4.4 迫零&#xff08;ZF&#xff09;检测算法 4.5 OCD_MMSE 检测算法 4.6 LAMA检测算法 …