Java uses Oracle database

Source: Internet
Author: User

ImportJava.sql.*; Public classOraclehelper {//Test Connection Function Public Static voidMain (String []args) {Derbyhelper de=NewDerbyhelper (); String SQL= "SELECT * from Users"; List<Object[]> list=de.querylist (SQL,NULL); for(intI=0;i<list.size (); i++) {Object []obj=List.get (i); System.out.println (obj[1].tostring () + "" +obj[2].tostring ());}} //Oracle Connection Property SettingsString driver= "Oracle.jdbc.driver.OracleDriver"; String URL= "Jdbc:oracle:thin:@10.62.140.54:1521:oracle1"; String User= "Scott"; String passwd= "1234";//connection class and interface definitionsConnection CT; PreparedStatement PS; ResultSet rs; PublicOraclehelper () {Try{class.forname (driver); CT=drivermanager.getconnection (URL,USER,PASSWD); } Catch(Exception e) {//TODO auto-generated Catch blocke.printstacktrace ();}} Public intUpdate (String sql,string []paras) {intCount=0;Try{PS=ct.preparestatement (SQL);//Injection ParametersSetparameters (paras);//The number of data rows updated. Count=ps.executeupdate ();} Catch(SQLException e) {//TODO auto-generated Catch blocke.printstacktrace ();}finally{ This. Close ();}returncount;}Private voidSetparameters (String[] paras)throwsSQLException {if(paras!=NULL&&!paras.equals ("")){     for(inti=0;i<paras.length;i++) {ps.setstring (i+1, Paras[i]); }}} PublicResultSet query (String sql,string[] paras) {Try{PS=ct.preparestatement (SQL); Setparameters (paras); Rs=ps.executequery ();} Catch(SQLException e) {//TODO auto-generated Catch blocke.printstacktrace ();}finally{//not off. }returnrs; } Public voidClose () {Try {if(rs!=NULL) Rs.close ();if(ps!=NULL) Ps.close ();if(ct!=NULL) Ct.close ();} Catch(SQLException e) {//TODO auto-generated Catch blocke.printstacktrace ();}} }

Java uses 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.