Advertisement
Guest User

TestJDBC2

a guest
Apr 24th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.44 KB | None | 0 0
  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 TESTJDBC2 {
  21.    
  22.     public static void main(String[] args) {
  23.         NadjiOdeljenje();
  24.     }
  25.    
  26.     public static void NadjiOdeljenje(){
  27.         String url = "jdbc:oracle:thin:@localhost:1521:orcl";
  28.         String upit = "select * from odeljenje";
  29.        
  30.         try (Connection konekcija = DriverManager.getConnection(url, "student", "student")){
  31.            
  32.             Statement stat = konekcija.createStatement();
  33.            
  34.             ResultSet rs = stat.executeQuery(upit);
  35.            
  36.             while(rs.next()){
  37.                 int sifraOdeljenja = rs.getInt(1);
  38.                 String nazivOdelj = rs.getString(2);
  39.                 String grad = rs.getString(3);
  40.                
  41.                 System.out.println(sifraOdeljenja + nazivOdelj + grad);
  42.              
  43.             }
  44.            
  45.            
  46.         } catch (SQLException ex) {
  47.             Logger.getLogger(TESTJDBC2.class.getName()).log(Level.SEVERE, null, ex);
  48.         }
  49.     }
  50.    
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement