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 lab_jdbc;
- /**
- *
- * @author student
- */
- import java.sql.*;
- import java.util.Properties;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- public class Lab_JDBC {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) throws SQLException {
- //KONEKT
- Connection conn = null;
- Properties connectionProps = new Properties();
- connectionProps.put("user", "inf127273");
- connectionProps.put("password", "inf127273");
- 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(Lab_JDBC.class.getName()).log(Level.SEVERE,
- "nie udało się połączyć z bazą danych", ex);
- System.exit(-1);
- }
- //DEKLARACJA STEJTMENT DO BAZY DANYCH
- Statement stmt = null;
- ResultSet rs = null; //RESULT wynik
- try {
- stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
- ResultSet.CONCUR_READ_ONLY);
- rs = stmt.executeQuery("SELECT COUNT(nazwisko) FROM pracownicy");
- while (rs.next()) {
- System.out.println(rs.getInt(1) + " " );
- }
- } catch (SQLException ex) {
- System.out.println("Bład wykonania polecenia" + ex.toString());
- }
- rs.close();//zamknij cztytacz
- rs = stmt.executeQuery("SELECT nazwisko,placa_pod FROM pracownicy where etat = 'ASYSTENT'"
- + "order by placa_pod DESC");
- while (rs.next()) {
- System.out.println(rs.getString(1) + " "+rs.getFloat(2));
- }
- rs.last();
- for (int i = 0; i < 2; i++) {
- rs.previous();
- }
- System.out.println(rs.getString(1));
- rs.close();
- stmt.close(); //zamknij stejtment
- //DISKONEKT
- try {
- conn.close();
- } catch (SQLException ex) {
- Logger.getLogger(Lab_JDBC.class.getName()).log(Level.SEVERE, null, ex);
- }
- System.out.println("DISKONEKT");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement