标签:cep statement acl for 准备 name try 对象 trace
JDBC驱动类:
com.mysql.jdbc.Driver
oracle.jdbc.driver.OracleDriver
JDBC URL:
jdbc:mysql://localhost:3306
jdbc:oracle:thin:@localhost:1521:orcl
1 try { 2 //1、加载驱动 3 Class.forName(JDBC驱动类); 4 } catch (ClassNotFoundException e) {System.out.println("加载驱动不成功");} 5 try { 6 //2、创建JDBC连接,其中有三个参数,分别是JDBC URL、数据库用户名和密码 7 Connection conn = DriverManager.getConnection(JDBC URL,数据库用户名,密码); 8 //3、创建Statement对象,准备执行SQL语句 9 Statement stmt = conn.createStatement(); 10 //4、执行SQL语句,返回结果(可能是结果集) 11 ResultSet rs = stmt.executeQuery("SELECT id, name FROM users"); 12 //5、操作结果集 13 while (rs.next()) { 14 int id = rs.getInt("id"); 15 String name = rs.getString("name"); 16 } 17 //6、关闭连接 18 conn.close(); 19 } catch (SQLException e) {e.printStackTrace();}
标签:cep statement acl for 准备 name try 对象 trace
原文地址:https://www.cnblogs.com/whirlwind/p/9940757.html