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 jbdc_nogalski;
- import java.sql.*;
- import java.util.Properties;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- /**
- *
- * @author student
- */
- public class JBDC_Nogalski {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- Connection conn = null;
- Properties connectionProps = new Properties();
- connectionProps.put("user", "inf132294");
- connectionProps.put("password", "inf132294");
- try {
- conn = DriverManager.getConnection("jdbc:oracle:thin:@//admlab2.cs.put.poznan.pl:1521/dblab02_students.cs.put.poznan.pl",connectionProps);
- System.out.println("Połączono z bazą danych");
- } catch (SQLException ex) {
- Logger.getLogger(JBDC_Nogalski.class.getName()).log(Level.SEVERE, "nie udało się połączyć z bazą danych", ex);
- System.exit(-1);
- }
- Statement stmt = null;
- ResultSet rs = null;
- try {
- stmt = conn.createStatement();
- rs = stmt.executeQuery("select count(*) " + "from pracownicy");
- while (rs.next()) {
- System.out.println("Zatrudniono " + rs.getInt(1) + "Pracowników, w tym:");
- }
- } catch (SQLException ex) {
- System.out.println("Bład wykonania polecenia" + ex.toString());
- } finally {
- if (rs != null) {
- try {
- rs.close();
- } catch (SQLException e) {
- /* kod obsługi */
- }
- }
- if (stmt != null) {
- try {
- stmt.close();
- } catch (SQLException e) {
- /* kod obsługi */ }
- }
- }
- try {
- stmt = conn.createStatement();
- rs = stmt.executeQuery("select nazwisko, nazwa " + "from pracownicy JOIN zespoly");
- while (rs.next()) {
- System.out.println("Zatrudniono " + rs.getString(1) + "Pracowników, w tym:");
- }
- } catch (SQLException ex) {
- System.out.println("Bład wykonania polecenia" + ex.toString());
- } finally {
- if (rs != null) {
- try {
- rs.close();
- } catch (SQLException e) {
- /* kod obsługi */
- }
- }
- if (stmt != null) {
- try {
- stmt.close();
- } catch (SQLException e) {
- /* kod obsługi */ }
- }
- }
- try {
- conn.close();
- System.out.println("Rozłączono z bazą danych");
- } catch (SQLException ex) {
- Logger.getLogger(JBDC_Nogalski.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- }
Add Comment
Please, Sign In to add comment