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 );