MyEclipse connecting Oracle databases in the Java language

Source: Internet
Author: User

Java connection to Oracle database under MyEclipse

First step: New Java Project.

Fill in the project name, other settings by default, click Done.

Create a new Java class, fill in the package name and class name, tick public static void main (String [] args), and click Done.

Step Two: Add Oracle Drive.

Under Libraries, click Add Extra Jar Package

Click OK after adding

At this point the project directory has been driven.

Step three: Write code tests

Add the following code to the Orcltest.java file:

Package OPERATEORCL;

import java.sql.Connection;

import Java.sql.DriverManager;

import Java.sql.ResultSet;

import java.sql.Statement;

Public class orcltest {

Public Static void Main (string[] args) {

TODO auto-generated Method stub

Basedao Basedao = new Basedao ();

Connection con = basedao.getconnection ();

if (con = = null) {

System. out. println ("Oracle database Connection failed");

} Else {

System. out. println ("Oracle database Connection succeeded");

}

}

}

class Basedao {

Private Static String URL = "Jdbc:oracle:thin: @localhost: 1521:ORCL";

Private Static String User = "C # #scott";

Private Static String Password = "Tiger";

Public Connection Conn;

Public Static Statement PS;

Public Static ResultSet rs;

Ways to connect to a database

Public Connection getconnection () {

Try {

Initializing the driver package

Class. forname ("Oracle.jdbc.OracleDriver");

According to the database connection character, name, password to Conn

System. out. println ("Start trying to connect to the database!") ");

conn = DriverManager. getconnection (URL, user, password);

} catch (Exception e) {

E.printstacktrace ();

}

return Conn;

}

}

Click Run to see the output: The Oracle connection is successful.

MyEclipse connecting Oracle databases in the Java language

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.