Oracle JDBC Insert Data Using CallableStatement Interface - BunksAllowed

BunksAllowed is an effort to facilitate Self Learning process through the provision of quality tutorials.

Community

Oracle JDBC Insert Data Using CallableStatement Interface

Share This



package com.t4b.jdbc.oracle.test; import java.sql.CallableStatement; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; public class TestMain { static { try { Class.forName("oracle.jdbc.driver.OracleDriver").newInstance(); } catch (Exception ex) { ex.printStackTrace(); } } public static void main(String[] args) { String name = "Python"; String author = "James"; String publisher = "Oxford"; Connection con = null; CallableStatement cstmt = null; try { con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:ORCL", "scott", "pass123"); cstmt = con.prepareCall("{call book_insert_proc(?,?,?)}"); cstmt.setString(1, name); cstmt.setString(2, author); cstmt.setString(3, publisher); cstmt.executeUpdate(); } catch (SQLException e) { e.printStackTrace(); } finally { if (con != null) { try { con.close(); } catch (SQLException e) { e.printStackTrace(); } } if (cstmt != null) { try { cstmt.close(); } catch (SQLException e) { e.printStackTrace(); } } } } }

Happy Exploring!

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.