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 lab01;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.util.Properties;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- /**
- *
- * @author student
- */
- public class Lab01 {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- Connection conn = null;
- Properties connectionProps = new Properties();
- connectionProps.put("user", "inf132310");
- connectionProps.put("password", "inf132310");
- 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");
- 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(id_prac) + " " + rs.getString(nazwisko) + " " + rs.getFloat(placa_pod));
- }
- }
- 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 */
- }
- }
- }
- }
- 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);
- }
- try {
- conn.close();
- // TODO code application logic here
- } catch (SQLException ex) {
- Logger.getLogger(Lab01.class.getName()).log(Level.SEVERE, null, ex);
- }
- System.out.println("exit db");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement