| 目次 |
|---|
|
・Thin Driver接続 ・JAVAソース |
import java.sql.*;
public class oracleDbConnect {
public static void main(String[] args){
Connection con = null;
PreparedStatement stmt = null;
ResultSet rs = null;
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
con = DriverManager.getConnection("
jdbc:oracle:thin:@10.92.168.1:1521:
instance_name","user","pass");
stmt = con.prepareStatement("select * from tbl_salary");
rs = stmt.executeQuery();
while(rs.next()){
System.out.print(rs.getInt(1));
System.out.print(rs.getInt(2));
System.out.print(rs.getInt(3));
}
}catch(SQLException e){
e.printStackTrace();
}catch (Exception e) {
e.printStackTrace();
}finally{
try {
if(rs != null){
rs.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
try {
if(stmt != null){
stmt.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
try {
if(con != null){
con.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}