Java connects Oracle database with JDBC to "reprint"

Source: Internet
Author: User

Java connects Oracle database with JDBC

(2011-03-15 00:10:03)

reprint http://blog.sina.com.cn/s/blog_61da86dd0100q27w.html

Java Connect Oracle steps:

1. Register Load Driver

Driver name: driver= "Oracle.jdbc.driver.OracleDriver";
Class.forName ("Driver class name");

2. Get the connection

Database address: Url= "JDBC:ORACLE:THIN:@127.0.0.1:1521:ORCL";
Connection conn = drivermanager.getconnection (database address, user name, password);
SYSTEM.OUT.PRINTLN ("Connection succeeded");

3. Perform operations on the database

4. Close the connection in turn
Conn.close ();

It is worth noting that:

1. You need to load the driver Class12.jar connected to Oracle during this process
2. Copy this jar package into 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 the fixed format: jdbc:oracle:thin:@ database IP Address: 1521: Global database name
Description:
Jdbc:oracle:thin: Represents the protocol, equivalent to "http:" for Internet use.
Database IP Address: Can be found by Ipconfig. At present the teacher machine found is: 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.
that is, the address written in the program is: JDBC:ORACLE:THIN:@192.168.1.199:1521:ORCL
6, start the Times wrong: Io exception: The Network Adapter could not establish the connection
Analysis One:
• To connect to a database, first make sure that the Oracle service is started. So start first: ORACLESERVICEORCL.
• Note that the client writes Java computers without the need to start any Oracle services on this computer.
run, the same error still exists.
Analysis Two:
• To access all network programs, the network program must run a program that listens on a port. To connect to Oracle, the Java program must first connect to the listener. For Oracle, this is the listening service: Oracleoracletnslistener. ORACLE10G's listener service name is different, but it is still the name ending with "Tnslistener".
7, if the monitoring service can start normally, the Java program can also connect to the Oracle database.

FAQ: Start the Monitoring service error, or no error after startup, but click "Refresh" to discover that it is not actually started. How to solve?
parse:

step:
Find the Oracle menu and find the "net Manager program →oracle NET configuration → local → listener → modify the text box on the right side of the host to the IP address of the native
must finally save the changes, Step: Click the menu "file" → "Save" network configuration.
start the Oracle monitoring service again and refresh to see if it started successfully.
if the listener service starts successfully, JDBC will normally be able to connect to Oracle as well.

as experience if "Tns:listener does not currently know of SID given in Connect D Escriptor ". You only need to restart the ORACLESERVICEORCL service again.
as an experience, if you do not connect using "localhost", use the native actual IP address, which is obtained through Ipconfig.
Finally, you should start the Oracle listener before you start the Oracle service.  

Attached: Port understanding and common port number

Port number: I'm. Similarly, in order to differentiate each network listener on the server, each listener is assigned a unique port number. The port number is equivalent to the "network program's identity ID."

Common port number: Sqlserver:1433;oracle:1521,web server: (http://g.cn, in fact, http://g.cn:80/), tomcat:8080

Line

Java connects Oracle database with JDBC to "reprint"

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.