导入jar包模式
import java.sql.*; public class jdbcdeno1 { public static void main(String[]
args){ // ("链接url+/数据库名","用户名","密码"); try(Connection connection= DriverManager.
getConnection("jdbc:mysql://localhost:3306/ooo","root","123456"); Statement
statement=connection.createStatement()) { //执行sql } catch (SQLException
throwables) { throwables.printStackTrace(); } } }
下面操作直接在//执行sql 下面那行复制粘贴就行
增:
向teacher表插入数据15号、名字为15,性别为女。
statement.executeUpdate("insert into teacher value (15,'十五','2')");
这里用“2”表示女是因为我直接写女的话报了一个“Data truncated for column ‘sex’ at row 1”的错。
插入多行(批处理):
statement.addBatch("insert into teacher value (15,'十五','2')"); statement.
addBatch("insert into teacher value (16,'16','2')"); statement.addBatch("insert
into teacher value (17,'17','1')"); statement.executeBatch();
删:
把刚插入的第15行数据删除
statement.executeUpdate("delete from teacher where tid='15'");
修:
把第14号的名字修改成14
statement.executeUpdate("update teacher set name='14' where tid='14'");