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 jdbc;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- /**
- *
- * @author FON
- */
- public class TESTJDBC2 {
- public static void main(String[] args) {
- NadjiOdeljenje();
- }
- public static void NadjiOdeljenje(){
- String url = "jdbc:oracle:thin:@localhost:1521:orcl";
- String upit = "select * from odeljenje";
- try (Connection konekcija = DriverManager.getConnection(url, "student", "student")){
- Statement stat = konekcija.createStatement();
- ResultSet rs = stat.executeQuery(upit);
- while(rs.next()){
- int sifraOdeljenja = rs.getInt(1);
- String nazivOdelj = rs.getString(2);
- String grad = rs.getString(3);
- System.out.println(sifraOdeljenja + nazivOdelj + grad);
- }
- } catch (SQLException ex) {
- Logger.getLogger(TESTJDBC2.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement