Java Connection Oracle Code

Source: Internet
Author: User

Tags: cat resultset off. SQL RET TCO database connection TST Generated

 PackageUtil;ImportJava.sql.*; Public classDbutil { Public StaticConnection getconnection () {Connection conn=NULL; Try{class.forname ("Oracle.jdbc.driver.OracleDriver");//Load Database driverSYSTEM.OUT.PRINTLN ("Database driver loaded successfully! ");//the output informationString url = "Jdbc:oracle:thin: @localhost: 1521:ORCL";//Get connection URLString user = "TEACHER";//Connect User nameString Password = "* * *";//Connection PasswordConnection con = drivermanager.getconnection (url, user, password);//Get database connection    if(Con! =NULL) {System.out.println ("Successful connection with Oracle database!! "); }    } Catch(Exception e) {e.printstacktrace (); }     returnConn//Returning Connection Instances    }    //ways to close resources         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 (); }            }}

Java Connection Oracle Code

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: