# Java与oracle数据库各种操作

```yaml
   Author: Gentleman.Hu
   Create Time: 2020-09-25 10:42:34
   Modified by: Gentleman.Hu
   Modified time: 2020-09-25 19:14:58
   Email: justfeelingme@gmail.com
   Home: https://crushing.xyz
   Description:
```

## Java与Oracle数据库各种操作

### 链接数据库

```java
//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();
```

1. 加载drive类
2. 建立连接
3. 通过Connection创建Statement对象
4. 建立ResultSet对象以接受Statement执行的query结果
5. 关闭连接

## 相关链接

* [Java Database Connectivity](https://www.javatpoint.com/example-to-connect-to-the-oracle-database)
* [Official Guide](https://docs.oracle.com/cd/E11882_01/appdev.112/e12137/getconn.htm#TDPJD127)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.crushing.xyz/java-ways/snippets/java-yu-oracle-shu-ju-ku-ge-zhong-cao-zuo.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
