Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * 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 oraclejdbc;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.sql.ResultSet;
- /**
- *
- * @author student
- */
- public class OracleJDBC {
- /**
- * @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("Blad sciezki 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.101:1521:xe", "hr", "hr");
- Statement stmt = connection.createStatement();
- ResultSet rs = stmt.executeQuery("query");
- 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("Blad polaczenia!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement