MyBatis学习笔记(一)
来源:互联网 发布:王柳雯淘宝店 编辑:程序博客网 时间:2024/04/29 18:57
原生JDBC连接方式:
Connection connection=null; PreparedStatement pst = null; ResultSet rs = null; try { //加载驱动 Class.forName("com.mysql.jdbc.Driver"); //建立连接 connection = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/book","root","root"); //编写sql语句 String sql = "select * from admin where name = ?"; //进行预编译 pst = connection.prepareStatement(sql); pst.setString(1, "amy"); //执行语句,返回结果集 rs = pst.executeQuery(); //循环输出 while(rs.next()){ System.out.println(rs.getString(1)+" "+rs.getString(3)); } } catch (Exception e) { e.printStackTrace(); }finally { rs.close(); pst.close(); connection.close(); }
可能存在的问题:
1、数据库资源的浪费,影响性能
2、如果sql语句总是需要修改,都需要重新编译,不利于维护
3、向PreparedStatement,ResultSet 里面设置值,不利于修改维护
注:如有错误,欢迎指正,谢谢!
0 0
- Mybatis学习笔记--(一)Mybatis基础
- MyBatis学习笔记(一)--初识MyBatis
- mybatis学习笔记(一)
- Mybatis学习笔记(一)
- Mybatis学习笔记(一)
- MyBatis学习笔记(一)
- MyBatis学习笔记(一)
- MyBatis学习笔记(一)
- MyBatis学习笔记(一)
- MyBatis学习笔记(一)
- MyBatis学习笔记(一)
- mybatis学习笔记(一)
- MyBatis学习笔记(一)
- MyBatis 学习笔记一
- MyBatis学习笔记一
- mybatis学习笔记一
- Mybatis学习笔记一
- # MyBatis学习笔记(一)快速入门
- 进程和线程(二)
- 深入浅出解释FFT(五)——FFT结果的物理意义
- Maven instal Could not resolve dependencies for project 找不到本地仓库下的jar
- CF
- 最小堆最大堆的详细解读
- MyBatis学习笔记(一)
- Android Studio中导入SlidingMenu(详解)
- poj1979 测试用例全通过,但提交就是WA,无解。
- 两台不同网段的PC直连是否可以相互ping通
- 倍增二分——玲珑学院OJ #1112
- 数据挖掘:K近邻
- 2016陕西省省赛 ACM Rui and her functions B 二分
- 修改linux(centos7)操作系统静态ip
- CF