Connecting to an Oracle database

Source: Internet
Author: User

Tags: SSE 2.0 print res instant picture installation result system

1. Connection Code

 PackageUtil;Importjava.sql.Connection;ImportJava.sql.DriverManager;Importjava.sql.PreparedStatement;ImportJava.sql.ResultSet;Importjava.sql.SQLException; Public classDbutil { Public  Static voidMain (String args[]) {Try{class.forname ("Oracle.jdbc.driver.OracleDriver"). newinstance (); } Catch(Instantiationexception | illegalaccessexception |classnotfoundexception e) {            //TODO auto-generated Catch blockE.printstacktrace (); } String User= "System"; String Password= "Password"; String URL= "Jdbc:oracle:thin: @localhost: 1521:orcl"; Connection Connection=NULL; Try{Connection=drivermanager.getconnection (Url,user,password); System.out.println ("Connection succeeded"); } Catch(SQLException e) {System.out.println ("Connection Failed");        E.printstacktrace (); }                    }     Public Static voidClose (Connection Connection) {Try {            if(Connection! =NULL) {connection.close (); }                    } Catch(SQLException e) {//TODO auto-generated Catch blockE.printstacktrace (); }    }     Public Static voidClose (PreparedStatement preparedstatement) {Try {            if(PreparedStatement! =NULL) {preparedstatement.close (); }                    } Catch(SQLException e) {//TODO auto-generated Catch blockE.printstacktrace (); }    }     Public Static voidClose (ResultSet ResultSet) {Try {            if(ResultSet! =NULL) {resultset.close (); }                    } Catch(SQLException e) {//TODO auto-generated Catch blockE.printstacktrace (); }    }    }

2. Load Driver

Bulid path->add External JARs find App\administrator\product\11.2.0\dbhome_1\jdbc\lib\ojbc6_g.jar under the Oracle installation path

3. Under Web-int, the Lib replicates a Ojbc6_g.jar

Connecting to an 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.

Tags Index: