Java connects to the Oracle database, javaoracle

Source: Internet
Author: User

Java connects to the Oracle database, javaoracle

Generally, an error is reported after the import oracle. jdbc. driver. *; statement is written. In this case, you need:


1. Add the JDBC driver to classpath

Two methods. 1. graphical, computer-properties-Advanced Settings-Environment Variable-edit PATH, add absolute PATH \ JDBC driver name such as C: \ jdbc \ lib \ ojdc6.jar; the JDBC driver has a version problem.

The second is cmd command line settings, C: \> set classpath =.; absolute path name \ JDBC driver name


2. Import the driver in your project

Because I am a newbie in JAVA, I always forget that there are not many content found on the Internet.

You need to right-click your project library to import the resource, such as ojdbc6.jar.

For example, if you want to use sdoapi. jar and sdoutl. jar provided by Oracle Spatial, you also need to import them here and add them to classpath in the previous step.


Connect to the Oracle database using java

Connection conn = null;
Class. forName ("oracle. jdbc. driver. OracleDriver"); // Add the oracle driver. "" contains the driver path.

String url = "jdbc: oracle: thin: @ MyDbComputerNameOrIP: 1521: ORCL"; // database connection. oracle indicates that the link is an oracle database; thin: @ MyDbComputerNameOrIP indicates the IP address of the database (thin can be retained :); 1521 indicates the port number of the database to be linked; ORCL indicates the Database Name

String UserName = "root"; // Database User Login Name (or schema name)

String Password = "2006"; // Password

Conn = DriverManager. getConnection (url, UserName, Password );

Connect to the Oracle database using java

Connection conn = null;
Class. forName ("oracle. jdbc. driver. OracleDriver"); // Add the oracle driver. "" contains the driver path.

String url = "jdbc: oracle: thin: @ MyDbComputerNameOrIP: 1521: ORCL"; // database connection. oracle indicates that the link is an oracle database; thin: @ MyDbComputerNameOrIP indicates the IP address of the database (thin can be retained :); 1521 indicates the port number of the database to be linked; ORCL indicates the Database Name

String UserName = "root"; // Database User Login Name (or schema name)

String Password = "2006"; // Password

Conn = DriverManager. getConnection (url, UserName, Password );

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.