Connect to the Oracle database through Java Testing

Source: Internet
Author: User
Java language test: connect to the Oracle database packagecom. linuxidc. jdbc; importjava. SQL. Connection; importjava. SQL. DriverManager; *** Test

Java language test Connection to the Oracle database package com. linuxidc. jdbc; import java. SQL. Connection; import java. SQL. DriverManager;/*** Test

Connect to the Oracle database through Java Testing

Package com. linuxidc. jdbc;

Import java. SQL. Connection;
Import java. SQL. DriverManager;
/**
* Test the connection to the oracle database
* @ Author wpc
*
*/

Public class JdbcSuccess {
// Driver, URL, user name, password
Private static final String driver = "oracle. jdbc. driver. OracleDriver ";
Private static final String url = "jdbc: oracle: thin: @ localhost: 1521: orcl ";
Private static final String username = "scott ";
Private static final String password = "929118 ";

Public static Connection getConnection (){
Connection connection = null;
Try {
// Load-driven
Class. forName (driver );
// Obtain the database connection through the driver management class
Connection = DriverManager. getConnection (url, username, password );
// Close the connection
Connection. close ();
} Catch (ClassNotFoundException e ){
E. printStackTrace ();
} Catch (Exception e ){
E. printStackTrace ();
}
Return connection;
}

// Test whether the oracle connection is successful
Public static void main (String [] args ){
Connection connection = JdbcSuccess. getConnection ();
If (connection! = Null ){
System. out. println ("connection to oracle Database successful:" + connection );
} Else {
System. out. println ("An error occurred while connecting to the oracle database !!! ");
}

}
}

This article permanently updates the link address:

,

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.