1 //call a stored procedure2 Public Static voidTestpro () {3String Driver = "Oracle.jdbc.OracleDriver";4String url = "Jdbc:oracle:thin: @localhost: 1521:orcl";5Connection conn =NULL;6CallableStatement cs =NULL;7 8 Try {9 Class.forName (driver);Tenconn = drivermanager.getconnection (URL, "Scott", "Tiger"); OneCS = Conn.preparecall ("{Call Countyearsal (?,?)}"); ACs.setint (1, 7369); - //types of registered Oracle output parameters -Cs.registeroutparameter (2, oracletypes.number); the Cs.execute (); - intYsal = Cs.getint (2); - System.out.println (ysal); -}Catch(Exception e) { + e.printstacktrace (); -}finally { + Try { A if(cs! =NULL){ at cs.close (); - } - if(Conn! =NULL){ - conn.close (); - } -}Catch(SQLException e) { in e.printstacktrace (); - } to } + } - //calling a stored function the Public Static voidTestfun () { *String Driver = "Oracle.jdbc.OracleDriver"; $String url = "Jdbc:oracle:thin: @localhost: 1521:orcl";Panax NotoginsengConnection conn =NULL; -CallableStatement cs =NULL; the + Try { A Class.forName (driver); theconn = drivermanager.getconnection (URL, "Scott", "Tiger"); +CS = Conn.preparecall ("{? =call countysal (?)}"); -Cs.setint (2, 7369); $ //types of registered Oracle output parameters $Cs.registeroutparameter (1, oracletypes.number); - Cs.execute (); - intYsal = Cs.getint (1); the System.out.println (ysal); -}Catch(Exception e) {Wuyi e.printstacktrace (); the}finally { - Try { Wu if(cs! =NULL){ - cs.close (); About } $ if(Conn! =NULL){ - conn.close (); - } -}Catch(SQLException e) { A e.printstacktrace (); + } the } -}
Java calls stored procedures and stored functions in Oracle