标签:select gets resultset while state creat next class 连接
java database connectivity(JDBC)是java提供的通用数据库连接api(相当于制定了一个连接规范,相应的数据库厂家编写实现这些规范的接口)
jdbc的流程
1. 加载数据库驱动
2. 获取数据库连接
3. 创建statement
4. 执行sql语句
5. 获取数据库结果集
6. 关闭相应数据库资源
Connection conn; Statement stmt; ResultSet rs = null; try { Class.forName(""); conn = DriverManager.getConnection("","",""); stmt = conn.createStatement(); String sql = "select * from user"; rs = stmt.executeQuery(sql); while(rs.next()){ System.out.println(rs.getString("columnName")); } rs.close(); stmt.close(); conn.close(); }catch (ClassNotFoundException e){ System.out.println("未找到相应的数据库驱动"); } catch (SQLException e) { e.printStackTrace(); }
标签:select gets resultset while state creat next class 连接
原文地址:https://www.cnblogs.com/zhangchiblog/p/8862075.html