1 / 7

Overview of JDBC

Overview of JDBC. CS348 Information System. Oracle JDBC. JDBC an API used for database connectivity. Creates Portable Applications. Basic Steps to develop JDBC Application. Import JDBC classes (java.sql.*). Load JDBC drivers. Connect and Interact with database. Disconnect from database.

enye
Download Presentation

Overview of JDBC

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Overview of JDBC CS348 Information System

  2. Oracle JDBC • JDBC an API used for database connectivity • Creates Portable Applications • Basic Steps to develop JDBC Application • Import JDBC classes (java.sql.*). • Load JDBC drivers • Connect and Interact with database • Disconnect from database

  3. Oracle JDBC • DriverManager provides basic services to manage set of JDBC drivers • Connection object sends queries to database server after a connection is set up • JDBC provides following three classes for sending SQL statements to server • StatementSQL statements without parameters • PreparedStatementSQL statements to be executed multiple times with different parameters • CallableStatementUsed for stored procedures

  4. Oracle JDBC • SQL query can be executed using any of the objects. (Statement,PreparedStatement,CallableStatement) • Syntax (Statement Object ) Public abstract ResultSet executeQuery(String sql) throws SQLException • Syntax (PreparedStatement,CallableStatement Object ) Public abstract ResultSet executeQuery() throws SQLException • Method executes SQL statement that returns ResultSet object (ResultSet maintains cursor pointing to its current row of data. )

  5. Oracle JDBC (Example) Import java.sql.*; Import java.io; Class simple{ public static void main(String[] args) throws Exception{ Connection conn=null; try{ String conStr = "jdbc:oracle:thin:@oracle.cs.purdue.edu:1521:orb"; DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver()); conn = DriverManager.getConnection(conStr,”username”,”passwd"); Statement cursor = conn.createStatement(); // Connection Est. ResultSet rset = stmt.executeQuery(“Select* from table_name”); while(rset.next()){ System.out.println(“Printing column name ”+rest.getStringVal(1)); } }Catch(ClassNotFoundException e){} cursor.close(); conn.close(); } }

  6. References • [1] Database Management Systems by Ramakrishnan and Gehrke

  7. Thank You

More Related