7、java jdbc如何连接oracle12
作者:互联网
1、导入依赖
<dependency> <groupId>com.oracle.database.jdbc</groupId> <artifactId>ojdbc8</artifactId> <version>12.2.0.1</version> </dependency>
2、创建jdbc连接实现查询
public class Test01 { public static void main(String[] args) throws Exception { //加载数据库驱动 Class.forName("oracle.jdbc.driver.OracleDriver"); //得到Connection连接 Connection connection = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:ORCL", "c##boat", "c##boat"); //得到预编译的Statement对象 PreparedStatement pstm = connection.prepareStatement("select * from student where id = ?"); //给参数赋值 pstm.setObject(1, 1); //执行数据库查询操作 ResultSet rs = pstm.executeQuery(); //输出结果 while(rs.next()){ System.out.println(rs.getString("name")); } //释放资源 rs.close(); pstm.close(); connection.close(); } }
标签:jdbc,java,rs,connection,oracle,close,oracle12,pstm 来源: https://www.cnblogs.com/M87-A/p/15269471.html