Eclipse Connect Oracle 11g Database Graphics tutorial

Source: Internet
Author: User
Tags connect create database

Eclipse is an open source, java-based, extensible development platform. Eclipse comes with a standard set of plug-ins, including Java development tools (Java Development kit,jdk).

1. First set up a project DB, right click DB, select Build Path-->configure built Path into

Through Add External JARs. Select D:orclapphrproduct11.2.0dbhome_1owbwflib under the Ojdbc14.jar, click OK.

2. Preparation of Connectoracle.java documents

Package Com.wuy;

Import java.sql.Connection;

Import Java.sql.DriverManager;

Import java.sql.SQLException;

public class Connectoracle {

Private Connection con;

Private String user= "Scott";

Private String user = "sys as SYSDBA";

Private String password= "18233188050";

Private String classname= "Oracle.jdbc.driver.OracleDriver";

Private String url= "JDBC:ORACLE:OCI@LOCALHOST:1158:ORCL"; This URL may not be valid

Private String URL = "Jdbc:oracle:thin: @hr-PC:1521:ORCL"; hr-pc and 1521 are critical, i.e. there is no this in the listening string,

D:orclapphrproduct11.2.0dbhome_1networkadmintnsnames.ora This file is not, must be based on Tnsnames.ora this file to configure the URL path, otherwise there will be error!!!

Public Connectoracle () {

try{

Class.forName (ClassName);

SYSTEM.OUT.PRINTLN ("Load Database driver successful!");

}catch (ClassNotFoundException e) {

SYSTEM.OUT.PRINTLN ("Load Database driver failed!");

E.printstacktrace ();

}

}

/** CREATE DATABASE Connection * *

Public Connection Getcon () {

try {

Con=drivermanager.getconnection (Url,user,password);

SYSTEM.OUT.PRINTLN ("CREATE DATABASE connection succeeded!");

catch (SQLException e) {

System.out.print (con);

SYSTEM.OUT.PRINTLN ("CREATE DATABASE connection Failed!");

Con=null;

E.printstacktrace ();

}

return con;

}

public void closed () {

try{

if (con!=null) {

Con.close ();

}

}catch (SQLException e) {

System.out.println ("Close Con object failed!");

E.printstacktrace ();

}

}

public static void Main (string[] args)

{

Connectoracle c=new connectoracle ();

C.getcon ();

C.closed ();

}

}

3. Operation Result:

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.