1.是一款持久性层框架,简化jdbc开发
2.持久层:保证数据库的那一层代码(JAVAEE三层架构:表现层,业务层,持久层)
3.框架:半成本软件,可套用的软件基础代码模型,在此基础上开发,效劳会更高
jdbc缺点
1.硬编码:注册驱动,获取连接
2.操作繁琐:手动设置参数,手动封装结果
import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; public class DbUtil { public static final String URL = "jdbc:mysql://localhost:3306/imooc"; public static final String USER = "liulx"; public static final String PASSWORD = "123456"; public static void main(String[] args) throws Exception { //1.加载驱动程序 Class.forName("com.mysql.jdbc.Driver"); //2. 获得数据库连接 Connection conn = DriverManager.getConnection(URL, USER, PASSWORD); //3.操作数据库,实现增删改查 Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("SELECT user_name, age FROM imooc_goddess"); //如果有数据,rs.next()返回true while(rs.next()){ System.out.println(rs.getString("user_name")+" 年龄:"+rs.getInt("age")); } } }
MyBatis简化优势
1.获取链接信息,直接配置文件
2.自动完成设置参数,自动封装结果
标签:jdbc,String,rs,简介,用途,static,MyBatis,import,public From: https://www.cnblogs.com/yzx-sir/p/16860181.html