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:
,