1.添加数据

<%@ page language="java" import="java.sql.*" pageEncoding="UTF-8"%>
<html>
  <body>
   <%
   		Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/student?useUnicode=true&characterEncoding=UTF-8","root","123456");Statement stat=conn.createStatement();
   		System.out.println(conn);
   		//添加数据
   		String sql="insert into xmq(sno,name,sex) values('0011','张诺','男')";
   		int i=stat.executeUpdate(sql);
   		out.println("成功添加"+i+"行");
   		System.out.println(conn);
   		
   		stat.close();
   		conn.close();
    %>
  </body>
</html>

2.删除数据

<%@ page language="java" import="java.sql.*" pageEncoding="UTF-8"%>
<html>
  <body>
   <%
   		Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/student?useUnicode=true&characterEncoding=UTF-8","root","123456");
   		Statement stat=conn.createStatement();
   		//删除数据
   		String sql="delete from xmq where sno='0002'";
   		int i=stat.executeUpdate(sql);
   		out.println("成功删除"+i+"行");
   		
   		stat.close();
   		conn.close();
    %>
  </body>
</html>

3.修改数据

<%@ page language="java" import="java.sql.*" pageEncoding="UTF-8"%>
<html>
  <body>
   <%
   		Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/student?useUnicode=true&characterEncoding=UTF-8","root","123456");Statement stat=conn.createStatement();
   		//修改数据
   		String sql="update xmq set sex='女' where sno='0008'";
   		int i=stat.executeUpdate(sql);
   		out.println("成功修改"+i+"行");
   		
   		stat.close();
   		conn.close();
    %>
  </body>
</html>

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐