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