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