Oracle JDBC Fetch Data Using Statement Interface - BunksAllowed

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

Community

Oracle JDBC Fetch Data Using Statement Interface

Share This




package com.t4b.jdbc.oracle.test; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class TestMain { static { try { Class.forName("oracle.jdbc.driver.OracleDriver").newInstance(); } catch (Exception ex) { ex.printStackTrace(); } } public static void main(String[] args) { String publisher = "Oxford"; Connection con = null; Statement stmt = null; ResultSet rs = null; try { con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:ORCL", "scott", "pass123"); stmt = con.createStatement(); rs = stmt.executeQuery("select * from books where publisher='" + publisher + "'"); while (rs.next()) { System.out.println( rs.getString("name") + " : " + rs.getString("author") + " : " + rs.getString("publisher")); } } catch (SQLException e) { e.printStackTrace(); } finally { if (rs != null) { try { rs.close(); } catch (SQLException e) { e.printStackTrace(); } } if (con != null) { try { con.close(); } catch (SQLException e) { e.printStackTrace(); } } if (stmt != null) { try { stmt.close(); } catch (SQLException e) { e.printStackTrace(); } } } } }

Happy Exploring!

No comments:

Post a Comment

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