diff --git "a/13 \345\274\240\345\276\267\345\272\267/20230517 \351\251\261\345\212\250.md" "b/13 \345\274\240\345\276\267\345\272\267/20230517 \351\251\261\345\212\250.md" new file mode 100644 index 0000000000000000000000000000000000000000..566514b4b953e35f186d4e276d6464e27f982b77 --- /dev/null +++ "b/13 \345\274\240\345\276\267\345\272\267/20230517 \351\251\261\345\212\250.md" @@ -0,0 +1,68 @@ +```java +import java.sql.*; + +public class words { + public static void main(String[] args) { + try { + Statement stmt = register(); + select(stmt); + } catch (ClassNotFoundException e) { + throw new RuntimeException(e); + } catch (SQLException e) { + throw new RuntimeException(e); + } + } + public static Statement register() throws ClassNotFoundException, SQLException { + Class.forName("com.mysql.jdbc.Driver"); + //2.链接对象 + String url ="jdbc:mysql://localhost:3306/test"; + String username ="root"; + String password ="root"; + Connection conn = DriverManager.getConnection(url, username, password); + Statement stmt = conn.createStatement(); + return stmt; + } + public static void select(Statement stmt) throws SQLException { + String sql = "select * from student"; + ResultSet rs = stmt.executeQuery(sql); + while (rs.next()) { + int id =rs.getInt("id"); + String name = rs.getString("name"); + String sex = rs.getString("sex"); + System.out.println(id+" "+name+" "+sex); + } + } + + public static void insert(Statement stmt) throws SQLException { + String sql="insert into student values (4,'唐','女')"; + int i = stmt.executeUpdate(sql); + if (i>0){ + System.out.println("成功添加"); + }else{ + System.out.println("失败"); + } + } + + public static void update(Statement stmt) throws SQLException { + String sql="update student set sex='男' where id=2"; + int i = stmt.executeUpdate(sql); + if (i>0){ + System.out.println("修改成功"); + }else { + System.out.println("失败"); + } + } + + public static void deletes(Statement stmt) throws SQLException { + String sql="deletes from student where id=1 "; + int i = stmt.executeUpdate(sql); + if (i>0){ + System.out.println("删除成功"); + }else { + System.out.println("失败"); + } + } +} + +``` + diff --git "a/13 \345\274\240\345\276\267\345\272\267/20230520 \344\275\234\344\270\232.md" "b/13 \345\274\240\345\276\267\345\272\267/20230520 \344\275\234\344\270\232.md" new file mode 100644 index 0000000000000000000000000000000000000000..6bb3b5537cb725df0c053f00438d2190c8822388 --- /dev/null +++ "b/13 \345\274\240\345\276\267\345\272\267/20230520 \344\275\234\344\270\232.md" @@ -0,0 +1,80 @@ +``` +import java.sql.*; + +public class words { + public static void main(String[] args) { + try { + Statement stmt = register(); + select(stmt); + } catch (ClassNotFoundException e) { + throw new RuntimeException(e); + } catch (SQLException e) { + throw new RuntimeException(e); + } + } + public static Statement register() throws ClassNotFoundException, SQLException { + Class.forName("com.mysql.jdbc.Driver"); + //2.链接对象 + String url ="jdbc:mysql://localhost:3306/test"; + String username ="root"; + String password ="root"; + Connection conn = DriverManager.getConnection(url, username, password); + Statement stmt = conn.createStatement(); + return stmt; + } + public class test { + private int age; + private String name; + private String sex; + + public int getAge() { + return age; + } + + public void setAge(int age) { + this.age = age; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getSex() { + return sex; + } + + public void setSex(String sex) { + this.sex = sex; + } + + @Override + public String toString() { + return "test{" + + "age=" + age + + ", name='" + name + '\'' + + ", sex='" + sex + '\'' + + '}'; + } + + public test(int age, String name, String sex) { + this.age = age; + this.name = name; + this.sex = sex; + } + + public test() { + } + class te extends test{ + @Override + public int getAge() { + return super.getAge(); + } + } +} + +``` +