con = DriverManager.getConnection("jdbc:oracle:thin:@ 10.92.168.1:1521:instance_name","user","pass");//1行で書いてください上記のデータベース指定は
jdbc:oracle:thin:@データベースのIPアドレス:ポート名:DBインスタンス名,スキーマ,パスワードというように指定をします。
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(); } } } }