0
点赞
收藏
分享

微信扫一扫

jdbc 添加数据 示例代码 230222

茗越 2023-02-22 阅读 68

// 加载驱动类
Class.forName("com.mysql.jdbc.Driver");

// 获取信息
// 连接字符串 连接失败会报错
String url = "jdbc:mysql://localhost:3306/heighschool";
// 用户名
String user = "root";
// 密码
String password = "root123";
// 连接对象获取
Connection connection = DriverManager.getConnection(url, user, password);

// 测试
System.out.println(connection);

// 获得执行者
Statement statement = connection.createStatement();

// sql
String sql = "insert into student values(3,'jerry',65)";

// 干活(添加)
int i = statement.executeUpdate(sql);

System.out.println("受影响行数:" + i);

举报

相关推荐

0 条评论