SHARE
TWEET

Untitled

a guest Jun 18th, 2019 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package oraclejdbc;
  7.  
  8. import java.sql.Connection;
  9. import java.sql.DriverManager;
  10. import java.sql.SQLException;
  11. import java.sql.Statement;
  12. import java.sql.ResultSet;
  13.  
  14.  
  15. /**
  16.  *
  17.  * @author student
  18.  */
  19. public class OracleJDBC {
  20.  
  21.     /**
  22.      * @param args the command line arguments
  23.      */
  24.     public static void main(String[] args) {
  25.         System.out.println("----------Polaczenie z baza danych Oracle ------");
  26.         try {
  27.           Class.forName("oracle.jdbc.driver.OracleDriver");
  28.         } catch (ClassNotFoundException e) {
  29.             System.out.println("Blad sciezki sterownika Oracle JDBC?");
  30.             e.printStackTrace();
  31.             return;
  32.         }
  33.        
  34.         System.out.println("Rejestracja sterownika Oracle JDBC!");
  35.         Connection connection = null;
  36.         try {
  37.             connection = DriverManager.getConnection(
  38.                     "jdbc:oracle:thin:@192.168.56.101:1521:xe", "hr", "hr");
  39.             Statement stmt = connection.createStatement();
  40.             ResultSet rs = stmt.executeQuery("query");
  41.             while(rs.next())
  42.                 System.out.println(rs.getInt(1)+"  "+rs.getString(2));
  43.         } catch(SQLException e) {
  44.             System.out.println("Blad polaczenia. Sprawdz konsole");
  45.             e.printStackTrace();
  46.             return;
  47.         }
  48.         if (connection != null) {
  49.             System.out.println("Polaczyles sie z baza danych oracle!");
  50.         } else{
  51.             System.out.println("Blad polaczenia!");
  52.         }
  53.        
  54.     }
  55.    
  56. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top