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;
- import java.sql.*;
- import java.util.Properties;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- /**
- *
- * @author student
- */
- public class Lab_JDBC {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- Connection conn = null;
- Properties connectionProps = new
- Properties();
- connectionProps.put("user", "inf127300");
- connectionProps.put("password", "inf127300");
- 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);
- }
- Statement stmt =
- null
- ;
- ResultSet rs =
- null
- ;
- try
- {
- stmt = conn.createStatement();
- rs = stmt.executeQuery(
- "select id_prac, nazwisko, placa_pod " +
- "from pracownicy"
- );
- while
- (rs.next()) {
- System.out.println(rs.getInt(1) +
- " "
- + rs.getString(2) +
- " "
- +
- rs.getFloat(3));
- }
- }
- 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();
- } catch (SQLException ex) {
- Logger.getLogger(Lab_JDBC.class.getName()).log(Level.SEVERE, null, ex);
- }
- System.out.println("Rozłączono");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement