package com.t4b.jdbc.oracle.test;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
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 publisher = "Willey";
Connection con = null;
CallableStatement cstmt = null;
ResultSet rs = null;
try {
con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:ORCL", "scott", "pass123");
cstmt = con.prepareCall("{call book_select_by_pub_proc(?)}");
cstmt.setString(1, publisher);
rs = cstmt.executeQuery();
while (rs.next()) {
System.out.println(
rs.getString("name") + " : " + rs.getString("author") + " : " + rs.getString("publisher"));
}
} 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();
}
}
}
}
}
Oracle JDBC Fetch Data Using CallableStatement Interface
Share This
Tags
# Java Database Connection
# Technology
Share This
About BunksAllowed
Technology
Labels:
Java Database Connection,
Technology
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.