SHARE
TWEET

Untitled

a guest Apr 27th, 2018 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package jdbc;
  7.  
  8. import java.sql.Connection;
  9. import java.sql.DriverManager;
  10. import java.sql.ResultSet;
  11. import java.sql.SQLException;
  12. import java.sql.Statement;
  13. import java.util.logging.Level;
  14. import java.util.logging.Logger;
  15.  
  16. /**
  17.  *
  18.  * @author FON
  19.  */
  20. public class JDBCTest1 {
  21.    
  22.     public static void main(String[] args) {
  23.         vratiOdeljenja();
  24.     }
  25.  
  26.     private static void vratiOdeljenja() {
  27.         String url = "jdbc:oracle:thin:@localhost:1521:orcl";
  28.         String upit = "select * from odeljenje";
  29.        
  30.         try (
  31.             Connection conn =
  32.                     DriverManager.getConnection(url, "student", "student");
  33.             Statement st = conn.createStatement();
  34.             ResultSet rs = st.executeQuery(upit);  
  35.             ) {
  36.            
  37.             while (rs.next()){
  38.                 int sifra = rs.getInt(1);
  39.                 String naziv = rs.getString("nazivodelj");
  40.                 String grad = rs.getString(3);
  41.                
  42.                 System.out.println("Sifra: " + sifra + ",naziv: " + naziv + ",grad: " + grad );
  43.             }
  44.         } catch (SQLException ex) {
  45.             Logger.getLogger(JDBCTest1.class.getName()).log(Level.SEVERE, null, ex);
  46.         }
  47.     }
  48.    
  49. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top