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 JDBCTest1 {
- public static void main(String[] args) {
- vratiOdeljenja();
- }
- private static void vratiOdeljenja() {
- String url = "jdbc:oracle:thin:@localhost:1521:orcl";
- String upit = "select * from odeljenje";
- try (
- Connection conn =
- DriverManager.getConnection(url, "student", "student");
- Statement st = conn.createStatement();
- ResultSet rs = st.executeQuery(upit);
- ) {
- while (rs.next()){
- int sifra = rs.getInt(1);
- String naziv = rs.getString("nazivodelj");
- String grad = rs.getString(3);
- System.out.println("Sifra: " + sifra + ",naziv: " + naziv + ",grad: " + grad );
- }
- } catch (SQLException ex) {
- Logger.getLogger(JDBCTest1.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement