Java Connection to Oracle database

Source: Internet
Author: User

 PackageShujuku;Importjava.sql.Connection;ImportJava.sql.DriverManager;Importjava.sql.PreparedStatement;ImportJava.sql.ResultSet;Importjava.sql.SQLException; Public classBasedao {Connection conn=NULL;    PreparedStatement PS; ResultSet RS=NULL; intrs1;  Public voidgetconnection () {Try{            //class.name Load DriverClass.forName ("Oracle.jdbc.driver.OracleDriver"); //Get Database linkConn=drivermanager.getconnection ("jdbc:oracle:thin:@20.12.2.50:1521:ora11g", "lzt02", "1"); }Catch(ClassNotFoundException e) {e.printstacktrace ();} Catch(Exception e) {e.printstacktrace (); }        //if (conn!=null) {System.out.println ("database link succeeded");}      }    //Close Link     Public voidCloseAll () {Try{                        if(rs!=NULL) {rs.close (); }            if(ps!=NULL) {ps.close (); }                        if(conn!=NULL) {conn.close (); }        }Catch(Exception e) {}}//Perform Actions     PublicResultSet execute (String sql,object[] params,intflag)        {getconnection (); Try{PS=conn.preparestatement (SQL); if(Params! =NULL)              {                 for(inti=0;i<params.length;i++) {Ps.setobject (i+1, Params[i]); }                                              }                        if(flag==0) {RS=Ps.executequery (); returnrs;} Else if(flag==1) {rs1=ps.executeupdate (SQL); if(rs1==1) {System.out.println ("Insert succeeded");} }                    }Catch(SQLException e) {e.printstacktrace ();} return NULL; }        //Public static void Main (string[] args) {//        //TODO auto-generated Method Stub//Basedao bd=new Basedao ();//bd.getconnection ();//    }}

Java Connection to 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.