import java.sql.*;
/*
create table customer (
no number(4) primary key,
name varchar(20),
email varchar(20),
tel varchar(20)
);
create or replace procedure sel_customer
(vname in customer.name%TYPE,
vemail out customer.email%TYPE,
vtel out customer.email%TYPE
)
is
begin
select email, tel into vemail, vtel
from customer
where name=vname;
end;
/
*/
class CallableStatementTest03{
public static void main(String[] args) {
Connection con=null;
String url="jdbc:oracle:thin:@{host name}:1521:{SID}";
// String url = "jdbc:odbc:{Data Source Name}";
String sql;
String name="..";
CallableStatement cs = null;
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
con = DriverManager.getConnection(url , "..", "..");
sql = "{call sel_customer(?,?,?)}";
cs = con.prepareCall(sql);
cs.setString(1, name);
cs.registerOutParameter(2, java.sql.Types.VARCHAR);
cs.registerOutParameter(3, java.sql.Types.VARCHAR);
cs.execute();
.. cs.getString(2) .. cs.getString(3) ..
cs.close();
con.close();
}catch(Exception e){
..
}
}
}
import java.sql.*;
/*
create table customer (
no number(4) primary key,
name varchar(20)
);
*/
class JDBC_Select2{
public static void main(String[] args) {
String driver="oracle.jdbc.driver.OracleDriver";
// String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
String url="jdbc:oracle:thin:@{host name}:1521:{SID}";
// String url = "jdbc:odbc:{Data Source Name}";
String user="..";
String pwd="..";
Connection con=null;
PreparedStatement pstmt= null;
String s_name;
String sql;
ResultSet rs = null;
try{
Class.forName(driver);
con = DriverManager.getConnection(url, user, pwd);
..
sql = "SELECT * FROM customer WHERE name LIKE ? ";
pstmt= con.prepareStatement(sql);
if( s_name.equals("") )
s_name = "%";
pstmt.setString(1, s_name);
rs = pstmt.executeQuery();
..
while( rs.next() ){
.. rs.getString("name") ..
} //while
rs.close();
pstmt.close();
con.close();
}catch(ClassNotFoundException e){
..
}catch(SQLException e){
..
}//try
catch(IOException e){
e.printStackTrace( );
}
}
}
import java.sql.*;
/*
create table customer (
no number(4) primary key,
name varchar(20)
);
*/
class JDBC_Select{
public static void main(String[] args) {
String driver="oracle.jdbc.driver.OracleDriver";
// String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
String url="jdbc:oracle:thin:@{host name}:1521:{SID}";
// String url = "jdbc:odbc:{Data Source Name}";
Connection con = null;
Statement stmt = null ;
ResultSet rs = null;
int no = 0;
String name, email, tel;
String sql;
try{
Class.forName(driver);
con = DriverManager.getConnection(url, "{ID}", "{password}" );
stmt= con.createStatement();
..
rs = stmt.executeQuery("SELECT * FROM customer");
while( rs.next() ){
.. rs.getInt("no") .. rs.getString("name") ..
}
}
catch(Exception e){
..
}
finally{
try{
if( rs != null ) rs.close();
if( stmt != null ) stmt.close();
if( con != null ) con.close();
}
catch(Exception e){
.. e.getMessage( ) ..
}
}
}
}