Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Zadanie 1-8
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package javaapplication1;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.sql.ResultSet;
- import java.io.*;
- /**
- *
- * @author student
- */
- public class JavaApplication1 {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- System.out.println("--------Polaczenie z baza danych Oracle -------");
- try{
- Class.forName("oracle.jdbc.driver.OracleDriver");
- } catch(ClassNotFoundException e){
- System.out.println("Rejestracja sterownika Oracle JDBC?");
- e.printStackTrace();
- return;
- }
- System.out.println("Rejestracja sterownika Oracle JDBC!");
- Connection connection = null;
- try {
- connection = DriverManager.getConnection("jdbc:oracle:thin:@192.168.56.106:1521:xe", "hr", "hr");
- Statement stmt = connection.createStatement();
- ResultSet rs=stmt.executeQuery("SELECT * FROM REGIONS");
- while(rs.next())
- System.out.println(rs.getInt(1)+" "+rs.getString(2));
- }
- catch(SQLException e){
- System.out.println("Blad polaczenia. sprawdz konsole");
- e.printStackTrace();
- return;
- }
- if(connection != null){
- System.out.println("polaczyles sie z baza danych oracle");
- }
- else{
- System.out.println("Nie udalo ie polaczyc z baza danych oracle");
- }
- try{
- connection.close();
- }
- catch(SQLException e){
- System.out.println("Nie dziala");
- }
- }
- }
- Zadanie 9/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package javaapplication1;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.sql.ResultSet;
- import java.io.*;
- /**
- *
- * @author student
- */
- public class JavaApplication1 {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- System.out.println("--------Polaczenie z baza danych Oracle -------");
- try{
- Class.forName("oracle.jdbc.driver.OracleDriver");
- } catch(ClassNotFoundException e){
- System.out.println("Rejestracja sterownika Oracle JDBC?");
- e.printStackTrace();
- return;
- }
- System.out.println("Rejestracja sterownika Oracle JDBC!");
- Connection connection = null;
- try {
- connection = DriverManager.getConnection("jdbc:oracle:thin:@192.168.56.106:1521:xe", "hr", "hr");
- Statement stmt = connection.createStatement();
- }
- catch(SQLException e){
- System.out.println("Blad polaczenia. sprawdz konsole");
- e.printStackTrace();
- return;
- }
- if(connection != null){
- System.out.println("polaczyles sie z baza danych oracle");
- }
- else{
- System.out.println("Nie udalo sie polaczyc z baza danych oracle");
- }
- try{
- connection.close();
- }
- catch(SQLException e){
- System.out.println("Nie dziala");
- }
- }
- }
- Zadanie 11-12
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package javaapplication1;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.sql.ResultSet;
- import java.io.*;
- /**
- *
- * @author student
- */
- public class JavaApplication1 {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) throws IOException{
- System.out.println("--------Polaczenie z baza danych Oracle -------");
- try{
- Class.forName("oracle.jdbc.driver.OracleDriver");
- } catch(ClassNotFoundException e){
- System.out.println("Rejestracja sterownika Oracle JDBC?");
- e.printStackTrace();
- return;
- }
- System.out.println("Rejestracja sterownika Oracle JDBC!");
- Connection connection = null;
- try {
- DataInputStream d = new DataInputStream(System.in);
- System.out.println("Podaj nazwe Uzytkownika");
- String tmp1=d.readLine();
- System.out.println("Podaj haslo uzytkownika");
- String tmp2=d.readLine();
- connection = DriverManager.getConnection("jdbc:oracle:thin:@192.168.56.106:1521:xe", tmp1, tmp2);
- // Statement stmt = connection.createStatement();
- // ResultSet rs=stmt.executeQuery("SELECT * FROM REGIONS");
- // while(rs.next())
- // System.out.println(rs.getInt(1)+" "+rs.getString(2));
- }
- catch(SQLException e){
- System.out.println("Blad polaczenia. sprawdz konsole");
- e.printStackTrace();
- return;
- }
- if(connection != null){
- System.out.println("polaczyles sie z baza danych oracle");
- }
- else{
- System.out.println("Nie udalo sie polaczyc z baza danych oracle");
- }
- try{
- connection.close();
- }
- catch(SQLException e){
- System.out.println("Nie dziala");
- }
- }
- }
- Zadanie 13-14
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement