JDBC
江军峰
这个作者很懒,什么都没留下…
展开
-
8 spring对JDBC的封装
1.首先创建一个表,塞点数据 2.创建一个Bean去接受它 **public class User_name { private String name; private String password; public String getName() { return name; } public void setName(String name) { this.name = name; } public St原创 2020-07-13 17:15:23 · 124 阅读 · 0 评论 -
7 JDBC Druid连接池的使用
1.工具类 (1)根据配置和工厂得到DataSource对象 //先获取配置 Properties properties = new Properties(); //获取路径 InputStream resourceAsStream = JDBC_util_2.class.getClassLoader().getResourceAsStream("druid.properties"); properties.l原创 2020-07-12 18:29:39 · 168 阅读 · 0 评论 -
6 JDBC对事务的管理
1.建账户表 2.未使用事务时 (1)代码 public class Damo5 { public boolean tran(int mon) { Connection con = null; PreparedStatement preparedStatement = null; PreparedStatement preparedStatement1 = null; try { con = JDBCutil.原创 2020-07-12 12:02:54 · 95 阅读 · 0 评论 -
5 登录示范(解决注入问题)
1.对于准备状态的认识 con = JDBCutil.getCon(); String sql="select * from user1 where name=? and password=?"; //使用准备状态解决注入问题 preparedStatement = con.prepareStatement(sql); //给占位符对号入座 preparedStatement.setS原创 2020-07-12 10:10:42 · 199 阅读 · 0 评论 -
4 JDBC工具类(将步骤简化)
1.工具类应包含 (1)获取con对象 public static Connection getCon() throws SQLException { return DriverManager.getConnection(url,name,pass); } (2)关闭资源 public static void close(Statement statement,Connection connection){ if (statement!=null){原创 2020-07-11 23:35:12 · 124 阅读 · 0 评论 -
3 将数据库中表中数据封装成集合对象
1.首先创造表头的类 public class stu { private int id; private String name; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } publi原创 2020-07-11 22:30:01 · 802 阅读 · 2 评论 -
2 JDBC遍历查询
1.代码 while(resultSet.next()){ int id = resultSet.getInt("id"); String name = resultSet.getString("name"); System.out.println("编号: "+id+" 姓名: "+name); } 2.结果 编号: 2 姓名:原创 2020-07-11 21:57:50 · 357 阅读 · 0 评论 -
1 JDBC查询的实现
1.数据库建表 2.代码实现 public class Demo1 { public static void main(String[] args) { Connection connection=null; Statement statement=null; ResultSet resultSet=null; try { //注册驱动 Class.forName("com.mysql原创 2020-07-11 21:50:17 · 155 阅读 · 0 评论