JDBC操作数据库——CRUD综合应用实例

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
RDS MySQL Serverless 高可用系列,价值2615元额度,1个月
云数据库 RDS PostgreSQL,高可用系列 2核4GB
简介:

通过一个综合型的例子加深对JDBC操作数据库的增、删、改、查的运用。

经典的图书信息录入实例


设计数据库

1
2
3
4
5
6
7
8
9
10
11
12
13
14
CREATE  TABLE  `tb_books`
(
   `id`  int (10) unsigned  NOT  NULL  AUTO_INCREMENT,
    
  ` name varchar (45)  NOT  NULL ,
    
  `price`  double  NOT  NULL ,
    
  `bookCount`  int (10) unsigned  NOT  NULL ,
    
  `author`  varchar (45)  NOT  NULL ,
    
  PRIMARY  KEY  (`id`)
)


wKioL1Lc1R6gdL0NAAHwzIdUb9A861.jpg


写一个Book类对图书信息进行封装

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package  com.lixiyu;
public  class  Book {
private  int  id;
private  String name;
private  double  price;
private  int  bookCount;
private  String author;
public  int  getId(){
     return  id;
}
public  void  setId( int  id){
     this .id=id;
}
public  String getName(){
     return   name;
}
public  void  setName(String name){
     this .name=name;
}
public  double  getPrice(){
     return  price;
}
public  void  setPrice( double  price){
     this .price=price;
}
public  int  getbookCount(){
     return  bookCount;
}
public  void  setbookCount( int  bookCount){
     this .bookCount=bookCount;
}
public  String getAuthor(){
     return  author;
}
public  void  setAuthor(String author){
     this .author=author;
}
}





添加(insert)图书信息操作


创建AddBook.jsp页面,用于对添加图书信息进行处理

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<%@ page language="java" contentType="text/html; charset=GB18030"
     pageEncoding="GB18030"%>
     <%@page import="java.sql.Connection"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.PreparedStatement"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
< html >
< head >
< meta  http-equiv = "Content-Type"  content = "text/html; charset=GB18030" >
< title >Insert title here</ title >
</ head >
< body >
<%request.setCharacterEncoding("UTF-8"); %>
< jsp:useBean  id = "book"  class = "com.lixiyu.Book" ></ jsp:useBean >
< jsp:setProperty  property = "*"  name = "book" />
<%
try{
     Class.forName("com.mysql.jdbc.Driver");//加载数据库驱动,注册到驱动管理器
     String url="jdbc:mysql://localhost:3306/db_test";//数据库连接字符串
     String username="root";//数据库用户名
     String password="lixiyu";//数据库密码
     Connection conn=DriverManager.getConnection(url,username,password);//创建Connection连接
     String sql="insert into tb_books(name,price,bookCount,author)values(?,?,?,?)";//添加图书信息sql语句
                                                                                                                                                                                                                                                                                                                                                                                                                        
     PreparedStatement ps=conn.prepareStatement(sql);//获取PreparedStatement
     ps.setString(1,book.getName());//对SQL语句中的第1个参数赋值
     ps.setDouble(2,book.getPrice());
     ps.setInt(3,book.getbookCount());
     ps.setString(4,book.getAuthor());//对SQL语句中的第4个参数赋值
     int row=ps.executeUpdate();//执行更新操作,返回所影响的行数
     if(row>0){
         out.print("成功添加了"+row+"条数据");
     }
     ps.close();
     conn.close();
}catch(Exception e){
     out.print("图书信息添加失败!");
     e.printStackTrace();
}
%>
</ body >
< a  href = "insert.jsp" >返回</ a >
</ html >


创建insert.jsp,用于创建添加图书信息所需的表单

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<%@ page language="java" contentType="text/html; charset=UTF-8"
     pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
< html >
< head >
< meta  http-equiv = "Content-Type"  content = "text/html; charset=UTF-8" >
< title >添加图书信息</ title >
< script  type = "text/javascript" >
     function check(form){
         with(form){
             if(name.value == ""){
                 alert("图书名称不能为空");
                 return false;
             }
             if(price.value == ""){
                 alert("价格不能为空");
                 return false;
             }
             if(author.value == ""){
                 alert("作者不能为空");
                 return false;
             }
             return true;
         }
     }
</ script >
</ head >
< body >
     < form  action = "AddBook.jsp"  method = "post"  onsubmit = "return check(this);" >
         < table  align = "center"  width = "450" >
             < tr >
                 < td  align = "center"  colspan = "2" >
                     < h2 >添加图书信息</ h2 >
                     < hr >
                 </ td >
             </ tr >
             < tr >
                 < td  align = "right" >图书名称:</ td >
                 < td >< input  type = "text"  name = "name"  /></ td >
             </ tr >
             < tr >
                 < td  align = "right" >价  格:</ td >
                 < td >< input  type = "text"  name = "price"  /></ td >
             </ tr >
             < tr >
                 < td  align = "right" >数  量:</ td >
                 < td >< input  type = "text"  name = "bookCount"  /></ td >
             </ tr >
             < tr >
                 < td  align = "right" >作  者:</ td >
                 < td >< input  type = "text"  name = "author"  /></ td >
             </ tr >
             < tr >
                 < td  align = "center"  colspan = "2" >
                     < input  type = "submit"  value = "添 加" >
                 </ td >
             </ tr >
         </ table >
     </ form >
</ body >
</ html >

最后运行

wKioL1Lc2WaiySd8AABt3y2sBH4326.jpg

成功:

wKiom1Lc2Yui_pabAABF1HO1eQA506.jpg



查询(select)图书信息操作


创建FindServlet的servlet对象用于查询所有图书的信息。编写doGet()方法,建立数据库连接,并将所有查询数据集合放置HttpServletRequest对象中,将请求转发到jsp页面中:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package  com.lixiyu;
import  java.io.IOException;
import  java.sql.Connection;
import  java.sql.DriverManager;
import  java.sql.ResultSet;
import  java.sql.SQLException;
import  java.sql.Statement;
import  java.util.ArrayList;
import  java.util.List;
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 FindServlet
  */
public  class  FindServlet  extends  HttpServlet {
     private  static  final  long  serialVersionUID = 1L;
                                                                                                                                                                                                                                                                                                                   
     /**
      * @see HttpServlet#HttpServlet()
      */
     public  FindServlet() {
         super ();
         // TODO Auto-generated constructor stub
     }
     /**
      * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
      */
     protected  void  doGet(HttpServletRequest request, HttpServletResponse response)  throws  ServletException, IOException {
         // TODO Auto-generated method stub
         try {
             Class.forName( "com.mysql.jdbc.Driver" );
             String url= "jdbc:mysql://localhost:3306/db_test" ;
             String username= "root" ;
             String password= "lixiyu" ;
             Connection conn=DriverManager.getConnection(url,username,password);
             Statement stmt=conn.createStatement(); //获取statement对象
             String sql= "select * from tb_books" ;
             ResultSet rs=stmt.executeQuery(sql);
             List<Book> list= new  ArrayList<Book>(); //实例化list对象
             while (rs.next()){
                 Book book= new  Book();
                 book.setId(rs.getInt( "id" )); //对id属性赋值
                 book.setName(rs.getString( "name" ));
                 book.setPrice(rs.getDouble( "price" ));
                 book.setbookCount(rs.getInt( "bookCount" ));
                 book.setAuthor(rs.getString( "author" ));
             list.add(book); //将图书对象添加到集合中
             }
             request.setAttribute( "list" , list); //将图书集合放置到request中
             rs.close(); //关闭ResultSet
             stmt.close(); //关闭Statement
             conn.close(); //关闭Connection
         } catch (ClassNotFoundException e){
             e.printStackTrace();
         } catch (SQLException e){
             e.printStackTrace();
         }
         request.getRequestDispatcher( "book_list.jsp" ).forward(request, response); //请求转发到book_List.jsp
     }
     /**
      * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
      */
     protected  void  doPost(HttpServletRequest request, HttpServletResponse response)  throws  ServletException, IOException {
         // TODO Auto-generated method stub
     }
}


在web.xml中添加映射:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
< welcome-file-list >
    < welcome-file >index.html</ welcome-file >
    < welcome-file >index.htm</ welcome-file >
    < welcome-file >index.jsp</ welcome-file >
    < welcome-file >default.html</ welcome-file >
    < welcome-file >default.htm</ welcome-file >
    < welcome-file >default.jsp</ welcome-file >
  </ welcome-file-list >
  < servlet >
    < description ></ description >
    < display-name >FindServlet</ display-name >
    < servlet-name >FindServlet</ servlet-name >
    < servlet-class >com.lixiyu.FindServlet</ servlet-class >
  </ servlet >
  < servlet-mapping >
    < servlet-name >FindServlet</ servlet-name >
    < url-pattern >/FindServlet</ url-pattern >
  </ servlet-mapping >


创建book_list.jsp页面,用于显示查询到的所有图书信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<%@ page language="java" contentType="text/html; charset=UTF-8"
     pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@page import="java.util.List"%>
<%@page import="com.lixiyu.Book"%>
< html >
< head >
< meta  http-equiv = "Content-Type"  content = "text/html; charset=UTF-8" >
< title >所有图书信息</ title >
< style  type = "text/css" >
     td{font-size: 12px;}
     h2{margin: 0px}
                                                                                                                                                                                                                                                                                                  
</ style >
</ head >
< body >
     < table  align = "center"  width = "450"  border = "1"  height = "180"  bordercolor = "white"  bgcolor = ""  cellpadding = "1"  cellspacing = "1" >
         < tr  bgcolor = "white" >
             < td  align = "center"  colspan = "5" >
                 < h2 >所有图书信息</ h2 >
             </ td >
         </ tr >
         < tr  align = "center"  bgcolor = "#e1ffc1"  >
             <!--  <td><b>ID</b></td>-->
             < td >< b >图书名称</ b ></ td >
             < td >< b >价格</ b ></ td >
             < td >< b >数量</ b ></ td >
             < td >< b >作者</ b ></ td >
         </ tr >
             <%
                 // 获取图书信息集合
                     List< Book >list = (List< Book >)request.getAttribute("list");
                     // 判断集合是否有效
                     if(list == null || list.size() <  1 ){
                         out.print("没有数据!");
                     }else{
                         // 遍历图书集合中的数据
                         for(Book book : list){
             %>
                 < tr  align = "center"  bgcolor = "white" >
                     <!--<td><%=book.getId()%></td>-->
                     < td ><%=book.getName()%></ td >
                     < td ><%=book.getPrice()%></ td >
                     < td ><%=book.getbookCount()%></ td >
                     < td ><%=book.getAuthor()%></ td >
                 < td >
                 < form  action = "UpdateServlet"  method = "post"  onsubmit = "return check(this);" >
                 < input  type = "hidden"  name = "id"  value="<%=book.getId()%>">
                 < input  type = "text"  name = "bookCount"  size = "3" >
                                                                                                                                                                                                                                                                                                              
                 </ form >
                                                                                                                                                                                                                                                                                                              
                 </ tr >
                                                                                                                                                                                                                                                                                                              
             <%
                     }
                 }
             %>
     </ table >
     < br >
</ body >
</ html >


创建index.jsp主页,用于请求查看所有图书信息:

1
2
3
< body >
< a  href = "FindServlet" >查看所有图书</ a >
</ body >

运行该实例

wKioL1Lc3QTylxv_AABOjiFfdvU910.jpg

wKiom1Lc3SiR9yGMAACeYDmI6lY322.jpg



修改(update)图书信息操作


在book_list.jsp中添多一列修改:

1
2
3
4
5
6
< td >
                 < form  action = "UpdateServlet"  method = "post"  onsubmit = "return check(this);" >
                 < input  type = "hidden"  name = "id"  value="<%=book.getId()%>">
                 < input  type = "text"  name = "bookCount"  size = "3" >
                 < input  type = "submit"  value = "修改" >
                 </ form ></ td >


创建UpdateServlet.jsp编写doPost方法对图书信息请求进行处理:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package  com.lixiyu;
import  java.io.IOException;
import  java.sql.Connection;
import  java.sql.DriverManager;
import  java.sql.PreparedStatement;
import  javax.servlet.ServletException;
import  javax.servlet.http.HttpServlet;
import  javax.servlet.http.HttpServletRequest;
import  javax.servlet.http.HttpServletResponse;
/**
  * Servlet implementation class UpdateServlet
  */
public  class  UpdateServlet  extends  HttpServlet {
     private  static  final  long  serialVersionUID = 1L;
     protected  void  doPost(HttpServletRequest request, HttpServletResponse response)  throws  ServletException, IOException {
         int  id = Integer.valueOf(request.getParameter( "id" ));
         int  bookCount = Integer.valueOf(request.getParameter( "bookCount" ));
         try  {
             // 加载数据库驱动,注册到驱动管理器
             Class.forName( "com.mysql.jdbc.Driver" );
             // 数据库连接字符串
             String url =  "jdbc:mysql://localhost:3306/db_test" ;
             // 数据库用户名
             String username =  "root" ;
             // 数据库密码
             String password =  "lixiyu" ;
             // 创建Connection连接
             Connection conn = DriverManager.getConnection(url,username,password);
             // 更新SQL语句
             String sql =  "update tb_books set bookcount=? where id=?" ;
             // 获取PreparedStatement
             PreparedStatement ps = conn.prepareStatement(sql);
             // 对SQL语句中的第一个参数赋值
             ps.setInt( 1 , bookCount);
             // 对SQL语句中的第二个参数赋值
             ps.setInt( 2 , id);
             // 执行更新操作
             ps.executeUpdate();
             // 关闭PreparedStatement
             ps.close();
             // 关闭Connection
             conn.close();
         catch  (Exception e) {
             e.printStackTrace();
         }
         // 重定向到FindServlet
         response.sendRedirect( "FindServlet" );
     }
}

添加xml映射

1
2
3
4
5
6
7
8
9
< servlet >
     < display-name >UpdateServlet</ display-name >
     < servlet-name >UpdateServlet</ servlet-name >
     < servlet-class >com.lixiyu.UpdateServlet</ servlet-class >
   </ servlet >
   < servlet-mapping >
     < servlet-name >UpdateServlet</ servlet-name >
     < url-pattern >/UpdateServlet</ url-pattern >
   </ servlet-mapping >


运行后

wKiom1Lc4FfSbOO9AAD9RNsUFKY761.jpg

wKiom1Lc4GbCah6KAAEDugnF2Y4344.jpg



删除(delete)图书信息操作


编写删除操作的servlet,命名为DeleteServlet:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package  com.lixiyu;
import  java.io.IOException;
import  java.sql.Connection;
import  java.sql.DriverManager;
import  java.sql.PreparedStatement;
import  javax.servlet.ServletException;
import  javax.servlet.http.HttpServlet;
import  javax.servlet.http.HttpServletRequest;
import  javax.servlet.http.HttpServletResponse;
/**
  * Servlet implementation class DeleteServlet
  */
public  class  DeleteServlet  extends  HttpServlet {
     private  static  final  long  serialVersionUID = 1L;
                                                                                                                                          
     protected  void  doGet(HttpServletRequest request, HttpServletResponse response)  throws  ServletException, IOException {
         // 获取图书id
         int  id = Integer.valueOf(request.getParameter( "id" ));
         try  {
             // 加载数据库驱动,注册到驱动管理器
             Class.forName( "com.mysql.jdbc.Driver" );
             // 数据库连接字符串
             String url =  "jdbc:mysql://localhost:3306/db_test" ;
             // 数据库用户名
             String username =  "root" ;
             // 数据库密码
             String password =  "lixiyu" ;
             // 创建Connection连接
             Connection conn = DriverManager.getConnection(url,username,password);
             // 删除图书信息的SQL语句
             String sql =  "delete from tb_books where id=?" ;
             // 获取PreparedStatement
             PreparedStatement ps = conn.prepareStatement(sql);
             // 对SQL语句中的第一个占位符赋值
             ps.setInt( 1 , id);
             // 执行更新操作
             ps.executeUpdate();
             // 关闭PreparedStatement
             ps.close();
             // 关闭Connection
             conn.close();
         catch  (Exception e) {
             e.printStackTrace();
         }
         // 重定向到FindServlet
         response.sendRedirect( "FindServlet" );
     }
}

添加xml映射:

1
2
3
4
5
6
7
8
9
10
11
< servlet >
     < description ></ description >
     < display-name >DeleteServlet</ display-name >
     < servlet-name >DeleteServlet</ servlet-name >
     < servlet-class >com.lixiyu.DeleteServlet</ servlet-class >
   </ servlet >
   < servlet-mapping >
     < servlet-name >DeleteServlet</ servlet-name >
     < url-pattern >/DeleteServlet</ url-pattern >
   </ servlet-mapping >
</ web-app >


整合CRUD操作


在前面book_list.jsp页面中进行整合:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<%@ page language="java" contentType="text/html; charset=UTF-8"
     pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@page import="java.util.List"%>
<%@page import="com.lixiyu.Book"%>
< html >
< head >
< meta  http-equiv = "Content-Type"  content = "text/html; charset=UTF-8" >
< title >所有图书信息</ title >
< style  type = "text/css" >
td{font-size: 12px;}
h2{margin: 0px}
</ style >
</ head >
< body >
< table  align = "center"  width = "450"  border = "1"  height = "180"  bordercolor = "white"  bgcolor = ""  cellpadding = "1"  cellspacing = "1" >
< tr  bgcolor = "white" >
< td  align = "center"  colspan = "5" >
< h2 >所有图书信息</ h2 >
</ td >
</ tr >
< tr  align = "center"  bgcolor = "#e1ffc1"  >
<!--  <td><b>ID</b></td>-->
< td >< b >图书名称</ b ></ td >
< td >< b >价格</ b ></ td >
< td >< b >数量</ b ></ td >
< td >< b >作者</ b ></ td >
< td >< b >修改数量</ b ></ td >
< td >< b >删 除</ b ></ td >
</ tr >
<%
// 获取图书信息集合
List< Book >list = (List< Book >)request.getAttribute("list");
// 判断集合是否有效
if(list == null || list.size() <  1 ){
out.print("没有数据!");
}else{
// 遍历图书集合中的数据
for(Book book : list){
%>
< tr  align = "center"  bgcolor = "white" >
<!--<td><%=book.getId()%></td>-->
< td ><%=book.getName()%></ td >
< td ><%=book.getPrice()%></ td >
< td ><%=book.getbookCount()%></ td >
< td ><%=book.getAuthor()%></ td >
< td >
< form  action = "UpdateServlet"  method = "post"  onsubmit = "return check(this);" >
< input  type = "hidden"  name = "id"  value="<%=book.getId()%>">
< input  type = "text"  name = "bookCount"  size = "3" >
< input  type = "submit"  value = "修改" >
</ form >
</ td >
< td >< a  href="DeleteServlet?id=<%=book.getId() %>">删除</ a >
</ td >
</ tr >
<%
}
}
%>
</ table >
< br >
< center >
< form    action = "insert.jsp"  method = "post"  onsubmit = "return check(this);" >
  < input  type = "submit"  name = ""  value = "添加数据"  >
</ form ></ center >
</ body >
</ html >


将前面AddBook.jsp中的页面链接进行修改

1
< a  href = "FindServlet" >返回</ a >


因此整个操作都回归到book_list.jsp来显示了

运行

wKioL1Lc4ziS8nEnAABdTGVs-EI747.jpg

CRUD操作整合到一个页面显示:

wKiom1Lc416S0m57AAFWtV79j3M565.jpg



这次JDBC先写到这,下次有时间再总结一下批处理、调用存储过程、分页查询的相关操作。



本文转自lixiyu 51CTO博客,原文链接:http://blog.51cto.com/lixiyu/1353185,如需转载请自行联系原作者


相关实践学习
每个IT人都想学的“Web应用上云经典架构”实战
本实验从Web应用上云这个最基本的、最普遍的需求出发,帮助IT从业者们通过“阿里云Web应用上云解决方案”,了解一个企业级Web应用上云的常见架构,了解如何构建一个高可用、可扩展的企业级应用架构。
MySQL数据库入门学习
本课程通过最流行的开源数据库MySQL带你了解数据库的世界。 &nbsp; 相关的阿里云产品:云数据库RDS MySQL 版 阿里云关系型数据库RDS(Relational Database Service)是一种稳定可靠、可弹性伸缩的在线数据库服务,提供容灾、备份、恢复、迁移等方面的全套解决方案,彻底解决数据库运维的烦恼。 了解产品详情:&nbsp;https://www.aliyun.com/product/rds/mysql&nbsp;
相关文章
|
2月前
|
SQL Java 数据库连接
除了JDBC,还有哪些常见的数据库访问技术?
除了JDBC,还有哪些常见的数据库访问技术?
220 2
|
2月前
|
存储 人工智能 NoSQL
AI大模型应用实践 八:如何通过RAG数据库实现大模型的私有化定制与优化
RAG技术通过融合外部知识库与大模型,实现知识动态更新与私有化定制,解决大模型知识固化、幻觉及数据安全难题。本文详解RAG原理、数据库选型(向量库、图库、知识图谱、混合架构)及应用场景,助力企业高效构建安全、可解释的智能系统。
|
3月前
|
关系型数据库 MySQL 数据库
自建数据库如何迁移至RDS MySQL实例
数据库迁移是一项复杂且耗时的工程,需考虑数据安全、完整性及业务中断影响。使用阿里云数据传输服务DTS,可快速、平滑完成迁移任务,将应用停机时间降至分钟级。您还可通过全量备份自建数据库并恢复至RDS MySQL实例,实现间接迁移上云。
|
5月前
|
存储 关系型数据库 数据库
附部署代码|云数据库RDS 全托管 Supabase服务:小白轻松搞定开发AI应用
本文通过一个 Agentic RAG 应用的完整构建流程,展示了如何借助 RDS Supabase 快速搭建具备知识处理与智能决策能力的 AI 应用,展示从数据准备到应用部署的全流程,相较于传统开发模式效率大幅提升。
附部署代码|云数据库RDS 全托管 Supabase服务:小白轻松搞定开发AI应用
|
6月前
|
安全 druid Nacos
0 代码改造实现应用运行时数据库密码无损轮转
本文探讨了敏感数据的安全风险及降低账密泄漏风险的策略。国家颁布的《网络安全二级等保2.0标准》强调了企业数据安全的重要性。文章介绍了Nacos作为配置中心在提升数据库访问安全性方面的应用,并结合阿里云KMS、Druid连接池和Spring Cloud Alibaba社区推出的数据源动态轮转方案。该方案实现了加密配置统一托管、帐密全托管、双层权限管控等功能,将帐密切换时间从数小时优化到一秒,显著提升了安全性和效率。未来,MSE Nacos和KMS将扩展至更多组件如NoSQL、MQ等,提供一站式安全服务,助力AI时代的应用安全。
377 14
|
3月前
|
存储 弹性计算 Cloud Native
云原生数据库的演进与应用实践
随着企业业务扩展,传统数据库难以应对高并发与弹性需求。云原生数据库应运而生,具备计算存储分离、弹性伸缩、高可用等核心特性,广泛应用于电商、金融、物联网等场景。阿里云PolarDB、Lindorm等产品已形成完善生态,助力企业高效处理数据。未来,AI驱动、Serverless与多云兼容将推动其进一步发展。
189 8
|
4月前
|
存储 关系型数据库 MySQL
【赵渝强老师】MySQL数据库的多实例环境
MySQL多实例是指在一台服务器上运行多个MySQL服务,通过不同端口提供独立的数据服务。各实例共享安装程序,但使用各自的配置文件和数据文件,实现资源高效利用。本文详细介绍了如何通过“mysqld_multi”工具配置和启动多个MySQL实例,并演示了目录创建、初始化、配置文件修改及实例启动等操作步骤。
165 1
|
3月前
|
存储 弹性计算 安全
现有数据库系统中应用加密技术的不同之处
本文介绍了数据库加密技术的种类及其在不同应用场景下的安全防护能力,包括云盘加密、透明数据加密(TDE)和选择列加密。分析了数据库面临的安全威胁,如管理员攻击、网络监听、绕过数据库访问等,并通过能力矩阵对比了各类加密技术的安全防护范围、加密粒度、业务影响及性能损耗。帮助用户根据安全需求、业务改造成本和性能要求,选择合适的加密方案,保障数据存储与传输安全。
|
5月前
|
安全 Java Nacos
0代码改动实现Spring应用数据库帐密自动轮转
Nacos作为国内被广泛使用的配置中心,已经成为应用侧的基础设施产品,近年来安全问题被更多关注,这是中国国内软件行业逐渐迈向成熟的标志,也是必经之路,Nacos提供配置加密存储-运行时轮转的核心安全能力,将在应用安全领域承担更多职责。

热门文章

最新文章