Using JDBC to connect to the database, you need to load the Oracle JDBC driver and reference a Ojdbc5.jar library. Examples of concatenated strings:
Drivermanager.getconnection ("Jdbc:oracle:thin: @localhost: 1521: database ", " login name ", " password ");
1 ImportJava.sql.*;2 Public classDbconn {3 PrivateConnection conn =NULL;4 Publicdbconn () {5 This. conn = This. getconnection ();//Get database connection6 }7 /**Get Connection Class*/8 PublicConnection getconnection () {9 Try {Ten /*Here's the code for connecting to Oracle*/ One /*loading the JDBC driver for Oracle*/ AClass.forName ("Oracle.jdbc.driver.OracleDriver"); - //drivers that are connected to the driver system that are already registered will be loaded and connected in turn - //until a correct driver is found theConn=drivermanager.getconnection ("Jdbc:oracle:thin: @localhost: 1521:oracle", "admin", "123456");//established a connection to Oracle -}Catch(Exception e) { - e.printstacktrace (); - } + returnConn; - } + PublicConnection Getconn () {//Returns a connection A returnConn; at } -}
JDBC Connects to Oracle database