Java Connection Oracle steps:
1. Registration Load Driver
Driver name: driver= "Oracle.jdbc.driver.OracleDriver";
Class.forName ("Driver class name");
2. Get Connected
Database address: Url= "JDBC:ORACLE:THIN:@127.0.0.1:1521:ORCL";
Connection conn = drivermanager.getconnection (database address, username, password);
System.out.println ("connected successfully");
3. Do the operation of the database
4. Turn off the connection in turn
Conn.close ();
It is noteworthy that:
1. In this process, you need to load the driver Class12.jar
2 that connects Oracle, copy this jar package to a Java project, and add it to the build path.
3, expand the jar package, find the name of the driver class, and copy: Oracle.jdbc.driver.OracleDriver
4, the database is written according to a fixed format: jdbc:oracle:thin:@ database IP address: 1521: Global database name
Description:
Jdbc:oracle:thin: Represents a protocol, equivalent to "http:" for Internet use.
Database IP Address: You can find it with Ipconfig. At present, the teacher has found the machine: 192.168.1.199.
1521:oracle The port of the database, usually without modification.
Global database name: typically specified at installation time, the default is: ORCL.
The address written in the program is: JDBC:ORACLE:THIN:@192.168.1.199:1521:ORCL
6, startup times error: Io exception: The network Adapter could not establish The connection
Analysis one:
• To connect to a database, first make sure that Oracle services are started. So start first: ORACLESERVICEORCL.
• Note that the client writes a Java computer and does not need to start any Oracle services on this computer.
Run, the same error still exists.
Analysis II:
• To access all network programs, the network program must run a program that listens on one of the ports. To connect to Oracle, the Java program must first connect to the listener. For Oracle, this is the listening service: Oracleoracletnslistener. ORACLE10G's listening service name is different, but still the name ending with "Tnslistener".
7, if the listening service starts correctly, the Java program can also connect to the Oracle database.
Frequently asked Questions: Start the Listening service error, or do not start the error, but click "Refresh" found not actually started. How to solve.
Analysis:
The IP address of the Oracle listener is incorrect and the IP address must be changed to the IP address of this computer.
Steps:
• Find the Oracle menu and find the "NET Manager" program →oracle NET configuration → local → listener → modify the text box to the right of "host" to the IP address of this computer
• Finally, be sure to save the changes, step: Click the menu "file" → "Save" network configuration.
• Start the Oracle listening service again and refresh to see if it starts successfully.
• If the listening service starts successfully, JDBC can also be connected to Oracle under normal circumstances.
• As an experience, if the "Tns:listener does not currently know of the SID given in Connect descriptor" appears. You only need to restart the ORACLESERVICEORCL service again.
• As an experience, if the use of "localhost" is not connected, then use the actual IP address of the machine, through the ipconfig.
Finally, you should start the Oracle listener before you start the Oracle service.
Attached: Port understanding and common port number
Port number: I. Similarly, each listener assigns a unique port number to distinguish each network listener on the server. The port number, which is equivalent to the identity ID of the network program.
Common port number: Sqlserver:1433;oracle:1521,web server: (http://g.cn, actually is http://g.cn:80/), tomcat:8080 Line