Warning: include_once(): http:// wrapper is disabled in the server configuration by allow_url_include=0 in /home/users/2/moriya-h5/web/confrage/java/jdbc/oracle_connect/oracle_connect.html on line 2

Warning: include_once(http://www.confrage.com/bin/header.php): failed to open stream: no suitable wrapper could be found in /home/users/2/moriya-h5/web/confrage/java/jdbc/oracle_connect/oracle_connect.html on line 2

Warning: include_once(): Failed opening 'http://www.confrage.com/bin/header.php' for inclusion (include_path='.:/usr/local/php/5.6/lib/php') in /home/users/2/moriya-h5/web/confrage/java/jdbc/oracle_connect/oracle_connect.html on line 2
Oracleデータベースに接続 | Java | 株式会社CONFRAGE
Warning: include_once(/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/menu.php): failed to open stream: No such file or directory in /home/users/2/moriya-h5/web/confrage/java/jdbc/oracle_connect/oracle_connect.html on line 17

Warning: include_once(): Failed opening '/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/menu.php' for inclusion (include_path='.:/usr/local/php/5.6/lib/php') in /home/users/2/moriya-h5/web/confrage/java/jdbc/oracle_connect/oracle_connect.html on line 17
Thin Driver接続
まず、Oracleクライアントのjdbc配下のlibディレクトリにclasses12.jarを置きます。
次にjdbc\libにクラスパスを通します。
そして以下の記述でドライバをロードします。

Class.forName("oracle.jdbc.driver.OracleDriver");

クラスパスを通していない場合、ロードできません。

次に、以下の記述でデータベースを指定します。

con = DriverManager.getConnection("jdbc:oracle:thin:@
    10.92.168.1:1521:instance_name","user","pass");//1行で書いてください
上記のデータベース指定は

jdbc:oracle:thin:@データベースのIPアドレス:ポート名:DBインスタンス名,スキーマ,パスワード
というように指定をします。

JAVAソース
実際にJAVAでOracleデータベースに接続するには以下のように記述します。
テーブルはOracleで事前に作成しておく必要があります。

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();
            }
        }
    }
}

Back to top

Information

Warning: include_once(/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/side_bar.php): failed to open stream: No such file or directory in /home/users/2/moriya-h5/web/confrage/java/jdbc/oracle_connect/oracle_connect.html on line 137

Warning: include_once(): Failed opening '/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/side_bar.php' for inclusion (include_path='.:/usr/local/php/5.6/lib/php') in /home/users/2/moriya-h5/web/confrage/java/jdbc/oracle_connect/oracle_connect.html on line 137

Warning: include_once(/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/seo.php): failed to open stream: No such file or directory in /home/users/2/moriya-h5/web/confrage/java/jdbc/oracle_connect/oracle_connect.html on line 146

Warning: include_once(): Failed opening '/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/seo.php' for inclusion (include_path='.:/usr/local/php/5.6/lib/php') in /home/users/2/moriya-h5/web/confrage/java/jdbc/oracle_connect/oracle_connect.html on line 146