From a3df3654e81e1055e217c6d1e6184c2c07af4b50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E4=BF=8A=E4=BC=9F?= <2421084001@qq.com> Date: Thu, 18 May 2023 09:37:20 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...00\346\254\241\344\275\234\344\270\232.md" | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 "12 \346\236\227\344\277\212\344\274\237/0516 \347\254\254\344\270\200\346\254\241\344\275\234\344\270\232.md" diff --git "a/12 \346\236\227\344\277\212\344\274\237/0516 \347\254\254\344\270\200\346\254\241\344\275\234\344\270\232.md" "b/12 \346\236\227\344\277\212\344\274\237/0516 \347\254\254\344\270\200\346\254\241\344\275\234\344\270\232.md" new file mode 100644 index 0000000..7cdc30c --- /dev/null +++ "b/12 \346\236\227\344\277\212\344\274\237/0516 \347\254\254\344\270\200\346\254\241\344\275\234\344\270\232.md" @@ -0,0 +1,75 @@ + import java.sql.Connection; + import java.sql.DriverManager; + import java.sql.SQLException; + import java.sql.Statement; + + public class insert { + public static void main(String[] args) { + Statement str = null; + Connection con = null; + try { + Class.forName("com.mysql.jdbc.Driver"); + String url = "jdbc:mysql://localhost:3306/aaa?useSSL=false&characterEncoding=utf8"; + String usename = "root"; + String password = "root"; + con = DriverManager.getConnection(url, usename, password); + String sql = "insert into Student value(1,'老王','男'),(2,'老表','男')"; + str = con.createStatement(); + int i = str.executeUpdate(sql); + if (i > 0) { + System.out.println("插入成功"); + } else { + System.out.println("插入失败"); + } + } catch (ClassNotFoundException e) { + System.out.println("驱动包导入正常"); + } catch (SQLException e) { + System.out.println("mysql语法错误"); + } finally { + try { + str.close(); + con.close(); + } catch (SQLException e) { + throw new RuntimeException(e); + } + } + } + } + import java.sql.Connection; + import java.sql.DriverManager; + import java.sql.SQLException; + import java.sql.Statement; + + public class delect { + public static void main(String[] args) { + Statement str = null; + Connection con = null; + try { + Class.forName("com.mysql.jdbc.Driver"); + String url = "jdbc:mysql://localhost:3306/aaa?useSSL=false&characterEncoding=utf8"; + String usename = "root"; + String password = "root"; + con = DriverManager.getConnection(url, usename, password); + String sql = "delete from Student where id=4"; + str = con.createStatement(); + int i = str.executeUpdate(sql); + if (i > 0) { + System.out.println("删除成功"); + } else { + System.out.println("删除失败"); + } + } catch (ClassNotFoundException e) { + System.out.println("导包异常"); + } catch (SQLException e) { + System.out.println("mysql语法错误"); + } finally { + try { + str.close(); + con.close(); + } catch (SQLException e) { + throw new RuntimeException(e); + } + } + } + } + -- Gitee