Java Connection Implementation code for Oracle database

Source: Internet
Author: User

  

 Packageconnectionoracledatabase;Importjava.sql.Connection;ImportJava.sql.DatabaseMetaData;ImportJava.sql.DriverManager;Importjava.sql.PreparedStatement;ImportJava.sql.ResultSet;Importjava.sql.SQLException; Public classConnectionoracledatabaseutil {/*** This is a successful case of connecting Oracle database *@paramargs*/     Public Static voidMain (string[] args) {//get database Information after Java connection to Oracle//establishing a connection to an Oracle databaseConnection con =NULL;//Create a connection to a databasePreparedStatement pre =NULL;//Create precompiled statement objects, usually with this instead of statementResultSet result =NULL;//Create a result set object        Try        {            Try{class.forname ("Oracle.jdbc.driver.OracleDriver"); } Catch(ClassNotFoundException e) {//TODO auto-generated Catch blockE.printstacktrace (); }//load the Oracle driverSystem.out.println ("Start trying to connect to the database!") "); String URL= "Jdbc:oracle:" + "thin: @localhost: 1521:ORCL";//127.0.0.1 is a native address, XE is the default database name for Lite OracleString user = "System";//user name, system default account nameString password = "910214";//The password you selected when you installed the settingscon = drivermanager.getconnection (url, user, password);//Get Connections//Get database DetailsDatabaseMetaData Dbmd =Con.getmetadata (); //gets the maximum number of connections supported by the database            intCount =dbmd.getmaxconnections (); System.out.println ("The maximum number of connections supported by the database is:" +count); }        Catch(SQLException ex) {System.out.println ("Connection exception:" +ex.getmessage ()); }    }}

Java Connection Implementation code for Oracle database

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.