Because Eclipse is an open source product, many of the tools are installed in the form of plug-ins that users choose to install, and many articles mention how to connect to the database, but there is no indication of how the database needs to be loaded and how to load it. jar, now added as follows,
To the Feast of posterity!
1. Under D:\oracle\ora92\jdbc\lib (your Oracle installation directory) there are many. jar package files, copy the Ojdbc14.jar to your project, right-click the file, select "Build Path" to select the "Import" option, You can now open and use the class file under the package. Of course, you can also, put the driver in the CLASSPATH environment variable, the other class package settings are similar!
2. Loading and registering the driver.
Class.forName ("Oracle.jdbc.driver.OracleDriver");
After the driver is loaded, a driver object is typically created and automatically registered by calling Drivermanager.registerdriver ().
3, establish the connection.
Drivermanager.getconnection ("Jdbc:oracle:thin: @localhost: 1521:LC", Name,pass);
The standard syntax for the JDBC URL is as follows:
<protocol>:<subprotocol>:<data Source Identifier>
It is divided into three parts:
Protocol: Main communication protocol
Subprotocol: A minor communication protocol with its driver name
Data source identifier: sources
As shown in the previous example:
"Jdbc:oracle:thin" is a communication protocol, @ after the "valid host address, then the port number, the default is: 1521. Then your data source, you must know that the following is the username and password, of course, can also write the following forms:
Connection con= drivermanager.getconnection ("JDBC:ORACLE:THIN:NAME/PASS@LOCALHOST:1521:LC");
Returned a connection object to con,