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 0000000000000000000000000000000000000000..7cdc30c36b67fba2af4cfdeea1ce5fe7254efaa4 --- /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); + } + } + } + } +