JDBC Link MySQL and Oracle

Source: Internet
Author: User

    • Import java.sql.*;
The packages used in JDBC are almost always in import?java.sql.*;
    • Import Oracel or MySQL packages and load drivers in your project:
The classpath of the project and the classpath of the system are put in classpath, if it is placed in the classpath of the system, if the version is different, it may interfere with the different projects in the system, put under the project, reduce the coupling between the projects; Load Oracle Driver:
Class.forName ("Oracle.jdbc.driver.OracleDriver");
Load MySQL driver:
Class.forName ("Com.mysql.jdbc.Driver");
    • To establish a connection:
1.1. Establish an Oracle connection:
Connection conn = drivermanager.getconnection ("Jdbc:mysql://host:port/datebase", "User", "password");
2.1. Establish MySQL Connection:
Connection conn = drivermanager.getconnection ("Jdbc:mysql://host:port/datebase", "User", "password");
Import java.sql.*;p Ublic class Testjdbc {public    static void Main (string[] args) throws Exception {                //class.forna Me ("Com.mysql.jdbc.Driver");                Long start = System.currenttimemillis ();                New Com.mysql.jdbc.Driver ();                Connection conn = drivermanager.getconnection ("Jdbc:mysql://host:port/datebase", "User", "password");        Connection conn = drivermanager.getconnection ("Jdbc:mysql://localhost:3306/martin", "root", "admin");        Connection conn = drivermanager.getconnection ("jdbc:oracle:[email protected":p ort:datebase "," User "," password ");                SYSTEM.OUT.PRINTLN (conn);                SYSTEM.OUT.PRINTLN (conn);        Long end = System.currenttimemillis ();        SYSTEM.OUT.PRINTLN ("Establish connection time:" + (End-start));}    }

JDBC Link MySQL and Oracle

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.