Java与oracle数据库各种操作
Author: Gentleman.Hu
Create Time: 2020-09-25 10:42:34
Modified by: Gentleman.Hu
Modified time: 2020-09-25 19:14:58
Email: [email protected]
Home: https://crushing.xyz
Description:
Java与Oracle数据库各种操作
链接数据库
//step1 load the driver class
Class.forName("oracle.jdbc.driver.OracleDriver");
//step2 create the connection object
Connection con=DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:xe","system","oracle");
//step3 create the statement object
Statement stmt=con.createStatement();
//step4 execute query
ResultSet rs=stmt.executeQuery("select * from emp");
while(rs.next())
System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getString(3));
//step5 close the connection object
con.close();
加载drive类
建立连接
通过Connection创建Statement对象
建立ResultSet对象以接受Statement执行的query结果
关闭连接
相关链接
Last updated
Was this helpful?