您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
05_JDBC各个类详解_DriverManager_获取数据库连接
发布时间:2022-07-17 17:10:25编辑:雪饮阅读()
package day5;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.SQLException;
public class JdbcTest {
public static void main(String[] args) throws Exception {
//继上篇之后本篇继续进行jdbc语法简化,这里就是获取数据库连接的简化,当直接连接本地localhost并且是3306端口时可以直接省略localhost:3306
//虽然可以这样写,但是哥不建议
Connection conn= DriverManager.getConnection("jdbc:mysql:///test","root","root");
//定义要执行的sql
String sql="update t4 set name='kk22080702' where id=1";
//执行sql
int effect_rows=conn.createStatement().executeUpdate(sql);
System.out.println(effect_rows);
}
}
关键字词:jdbc,数据库,连接