SHARE
TWEET

Untitled

a guest Jun 18th, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Zadanie 1-8
  2. /*
  3.  * To change this license header, choose License Headers in Project Properties.
  4.  * To change this template file, choose Tools | Templates
  5.  * and open the template in the editor.
  6.  */
  7. package javaapplication1;
  8.  
  9. import java.sql.Connection;
  10. import java.sql.DriverManager;
  11. import java.sql.SQLException;
  12. import java.sql.Statement;
  13. import java.sql.ResultSet;
  14. import java.io.*;
  15. /**
  16.  *
  17.  * @author student
  18.  */
  19. public class JavaApplication1 {
  20.    
  21.    
  22.     /**
  23.      * @param args the command line arguments
  24.      */
  25.     public static void main(String[] args) {
  26.         System.out.println("--------Polaczenie z baza danych Oracle -------");
  27.     try{
  28.         Class.forName("oracle.jdbc.driver.OracleDriver");
  29.     } catch(ClassNotFoundException e){
  30.         System.out.println("Rejestracja sterownika Oracle JDBC?");
  31.         e.printStackTrace();
  32.         return;
  33.     }
  34.     System.out.println("Rejestracja sterownika Oracle JDBC!");
  35.     Connection connection = null;
  36.     try {
  37.         connection = DriverManager.getConnection("jdbc:oracle:thin:@192.168.56.106:1521:xe", "hr", "hr");
  38.         Statement stmt = connection.createStatement();
  39.         ResultSet rs=stmt.executeQuery("SELECT * FROM REGIONS");
  40.         while(rs.next())
  41.         System.out.println(rs.getInt(1)+"  "+rs.getString(2));
  42.     }
  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.     }
  51.     else{
  52.         System.out.println("Nie udalo ie polaczyc z baza danych oracle");
  53.     }
  54.     try{
  55.     connection.close();
  56.     }
  57.     catch(SQLException e){
  58.         System.out.println("Nie dziala");
  59.     }
  60.     }
  61.    
  62. }
  63.  
  64. Zadanie 9/*
  65.  * To change this license header, choose License Headers in Project Properties.
  66.  * To change this template file, choose Tools | Templates
  67.  * and open the template in the editor.
  68.  */
  69. package javaapplication1;
  70.  
  71. import java.sql.Connection;
  72. import java.sql.DriverManager;
  73. import java.sql.SQLException;
  74. import java.sql.Statement;
  75. import java.sql.ResultSet;
  76. import java.io.*;
  77. /**
  78.  *
  79.  * @author student
  80.  */
  81. public class JavaApplication1 {
  82.    
  83.    
  84.     /**
  85.      * @param args the command line arguments
  86.      */
  87.     public static void main(String[] args) {
  88.         System.out.println("--------Polaczenie z baza danych Oracle -------");
  89.     try{
  90.         Class.forName("oracle.jdbc.driver.OracleDriver");
  91.     } catch(ClassNotFoundException e){
  92.         System.out.println("Rejestracja sterownika Oracle JDBC?");
  93.         e.printStackTrace();
  94.         return;
  95.     }
  96.     System.out.println("Rejestracja sterownika Oracle JDBC!");
  97.     Connection connection = null;
  98.     try {
  99.         connection = DriverManager.getConnection("jdbc:oracle:thin:@192.168.56.106:1521:xe", "hr", "hr");
  100.         Statement stmt = connection.createStatement();
  101.     }
  102.     catch(SQLException e){
  103.         System.out.println("Blad polaczenia. sprawdz konsole");
  104.         e.printStackTrace();
  105.         return;
  106.     }
  107.     if(connection != null){
  108.         System.out.println("polaczyles sie z baza danych oracle");
  109.     }
  110.     else{
  111.         System.out.println("Nie udalo sie polaczyc z baza danych oracle");
  112.     }
  113.     try{
  114.     connection.close();
  115.     }
  116.     catch(SQLException e){
  117.         System.out.println("Nie dziala");
  118.     }
  119.     }
  120.    
  121. }
  122.  
  123. Zadanie 11-12
  124.  
  125. /*
  126.  * To change this license header, choose License Headers in Project Properties.
  127.  * To change this template file, choose Tools | Templates
  128.  * and open the template in the editor.
  129.  */
  130. package javaapplication1;
  131.  
  132. import java.sql.Connection;
  133. import java.sql.DriverManager;
  134. import java.sql.SQLException;
  135. import java.sql.Statement;
  136. import java.sql.ResultSet;
  137. import java.io.*;
  138. /**
  139.  *
  140.  * @author student
  141.  */
  142. public class JavaApplication1 {
  143.    
  144.    
  145.     /**
  146.      * @param args the command line arguments
  147.      */
  148.     public static void main(String[] args) throws IOException{
  149.         System.out.println("--------Polaczenie z baza danych Oracle -------");
  150.     try{
  151.         Class.forName("oracle.jdbc.driver.OracleDriver");
  152.     } catch(ClassNotFoundException e){
  153.         System.out.println("Rejestracja sterownika Oracle JDBC?");
  154.         e.printStackTrace();
  155.         return;
  156.     }
  157.     System.out.println("Rejestracja sterownika Oracle JDBC!");
  158.     Connection connection = null;
  159.     try {
  160.     DataInputStream d = new DataInputStream(System.in);
  161.     System.out.println("Podaj nazwe Uzytkownika");
  162.     String tmp1=d.readLine();
  163.     System.out.println("Podaj haslo uzytkownika");
  164.     String tmp2=d.readLine();
  165.         connection = DriverManager.getConnection("jdbc:oracle:thin:@192.168.56.106:1521:xe", tmp1, tmp2);
  166.       //  Statement stmt = connection.createStatement();
  167.      //   ResultSet rs=stmt.executeQuery("SELECT * FROM REGIONS");
  168.      //   while(rs.next())
  169.     //    System.out.println(rs.getInt(1)+"  "+rs.getString(2));
  170.  
  171.     }
  172.     catch(SQLException e){
  173.         System.out.println("Blad polaczenia. sprawdz konsole");
  174.         e.printStackTrace();
  175.         return;
  176.     }
  177.     if(connection != null){
  178.         System.out.println("polaczyles sie z baza danych oracle");
  179.     }
  180.     else{
  181.         System.out.println("Nie udalo sie polaczyc z baza danych oracle");
  182.     }
  183.     try{
  184.     connection.close();
  185.     }
  186.     catch(SQLException e){
  187.         System.out.println("Nie dziala");
  188.     }
  189.     }
  190.    
  191. }
  192.  
  193. Zadanie 13-14
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